[BUG] - Issue Title cse 2.8.20版本 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream流 int read()方法读取单字节,如果读取到流末尾会抛异常IndexOutOfBoundsException
还没有人认领这个 Issue。
评估
调研方向
从 org.apache.servicecomb.foundation.vertx.stream.BufferInputStream 开始,并使用 CseBufferInputStream.main 示例复现该问题。检查包装的 ByteBuf 到达末尾时 int read() 的行为,然后验证使用有效 gzip 数据的 gzipRead 也能在没有 IndexOutOfBoundsException 的情况下完成,并且流结束时返回 -1。
由索引模型根据 Issue 内容生成。
描述
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;
}
}
直接执行CseBufferInputStream.main()
运行结果
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
- 主要语言
- Java
- 星标
- 1.9k
- 派生
- 813
- 平均合并
- 8 天 23 小时
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/servicecomb-java-chassis 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
apache/servicecomb-java-chassis#5106 ·
-
question
难度 5/5 一周以上 新手友好度 35/100
apache/servicecomb-java-chassis#5153 · 1 条评论 ·
-
question
难度 4/5 3-5 天 新手友好度 25/100
apache/servicecomb-java-chassis#5146 ·
-
[FEATURE] - When will ServiceComb support Spring Boot 4.x, Spring Framework 7.x, and Jackson 3.x? 未关闭enhancement
难度 5/5 一周以上 新手友好度 25/100
apache/servicecomb-java-chassis#5145 ·
-
2.x bug
apache/servicecomb-java-chassis#5141 · 已指派 1 人 ·
查看 apache/servicecomb-java-chassis 的全部 Issue
相似的 Issue
-
area/plugin
难度 2/5 1-3 小时 新手友好度 75/100
kestra-io/plugin-kestra#190 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
apache/rocketmq-dashboard#5064 ·