You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "blacksea3 (via GitHub)" <gi...@apache.org> on 2025/04/11 12:29:30 UTC
[I] [BUG] - Issue Title cse 2.8.20版本 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException [servicecomb-java-chassis]
blacksea3 opened a new issue, #4778:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4778
### Steps to Reproduce
cse 2.8.20版本 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException
示例代码1: 单独构造失败用例
public class CseBufferInputStream {
public static void main(String[] args) throws IOException {
byte[] byteArray = new byte[10];
BufferedReader br = null;
try {
// 由于StsCseServerFilter要在此Filter之前执行,所以,需要重置码流,将ridx置0
InputStream inputStream = getRealInputStream(byteArray);
if (inputStream == null) {
return;
}
inputStream.reset();
while (inputStream.read() >= 0) {
;
}
} finally {
IOUtils.closeQuietly(br);
}
}
public static InputStream getRealInputStream(byte[] byteArray) {
// 创建 UnpooledSlicedByteBuf
ByteBuf slicedByteBuf = Unpooled.wrappedBuffer(byteArray);
// 创建 BufferInputStream,这个stream类型,以及里面的Buffer和真实的走CSE请求的一致
InputStream inputStream = new BufferInputStream(slicedByteBuf);
return inputStream;
}
}
运行结果
org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException

示例代码2: 实际应用
/**
* gzip解压
* @param byteArray gzip压缩数据
*
* @throws IOException IOException
*/
public static void gzipRead(byte[] byteArray) throws IOException {
BufferedReader br = null;
try {
// 由于StsCseServerFilter要在此Filter之前执行,所以,需要重置码流,将ridx置0
InputStream inputStream = getRealInputStream(byteArray);
if (inputStream == null) {
return;
}
inputStream.reset();
br = new BufferedReader(new InputStreamReader(new GZIPInputStream(inputStream), "UTF-8"));
char[] readBuff = new char[2048];
while ((br.read(readBuff)) > 0) {
}
} finally {
IOUtils.closeQuietly(br);
}
}
public static InputStream getRealInputStream(byte[] byteArray) {
// 创建 UnpooledSlicedByteBuf
ByteBuf slicedByteBuf = Unpooled.wrappedBuffer(byteArray);
// 创建 BufferInputStream,这个stream类型,以及里面的Buffer和真实的走CSE请求的一致
InputStream inputStream = new BufferInputStream(slicedByteBuf);
return inputStream;
}
调用gzipRead方法,传一个正确的gzip压缩二进制流进去, 在 java 1.8.0_432 会报错,其原因同 示例1一致,
int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException
详细调用链见图 java 1.8.0_432 见红色流程。

### Expected Behavior
org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 实现 java.io.InputStream
没字节的时候 应该返回-1,接口定义如下

### Servicecomb Version
2.8.20
### Additional Context
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [BUG] - Issue Title cse 2.8.20版本 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException [servicecomb-java-chassis]
Posted by "hezhangjian (via GitHub) via commits" <co...@servicecomb.apache.org>.
hezhangjian commented on issue #4778:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4778#issuecomment-6840450244
Thanks for the detailed reproducer.
As already pointed to in the earlier comment, [#5059](https://github.com/apache/servicecomb-java-chassis/pull/5059) was merged into `2.9.x` on 28 January 2026. The same `int read()` end-of-stream change was also merged into `2.8.x` in [#5063](https://github.com/apache/servicecomb-java-chassis/pull/5063) on 30 January 2026: when no bytes remain, `read()` returns `-1` instead of calling `readUnsignedByte()`.
The first published releases that contain this change are [2.8.30](https://github.com/apache/servicecomb-java-chassis/releases/tag/2.8.30) and [2.9.3](https://github.com/apache/servicecomb-java-chassis/releases/tag/2.9.3). Later 2.8.x / 2.9.x releases such as 2.8.31 and 2.9.5 include it as well. 2.8.20, and the earlier published 2.8.29 / 2.9.2 tags, still have the unguarded `read()` path.
Could you retry your reproducer on a published 2.8.30+ or 2.9.3+ release and tell us whether the `IndexOutOfBoundsException` is gone?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [BUG] - Issue Title cse 2.8.20版本 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException [servicecomb-java-chassis]
Posted by "chengyouling (via GitHub)" <gi...@apache.org>.
chengyouling commented on issue #4778:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4778#issuecomment-3803932796
see: https://github.com/apache/servicecomb-java-chassis/pull/5059
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [BUG] - Issue Title cse 2.8.20版本 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4778:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4778#issuecomment-2808668511
可以帮助提交一个PR修复这个问题吗?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org