B2InputStreamExcerpt casts remaining length to int, so parts over 2 GiB fail to read

未关闭 适合新手
#242 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

错误位于 core/src/main/java/com/backblaze/b2/util/B2InputStreamExcerpt.java 中的 getRemaining,它把 long 类型的差值强制转换为 int。请阅读该方法及其在第 69、85、96 行(read、skip、available)的调用方。一个单元测试包装一个带有 3 GiB 片段的流,并用小缓冲区调用 read,应能复现负长度。当长度被限制为 Integer.MAX_VALUE 且该测试通过时,即完成。

由索引模型根据 Issue 内容生成。

描述

What happens

getRemaining() returns (int) (pastEnd - iPosition). For an excerpt longer than Integer.MAX_VALUE bytes, the cast wraps to a negative number, and read, skip and available (which use it with Math.min) then pass a negative length down and fail. This affects only parts larger than 2 GiB.

Where

core/src/main/java/com/backblaze/b2/util/B2InputStreamExcerpt.java:146 (getRemaining), used at :69, :85 and :96.

Why it matters

Impact: Availability (an upload of such a part fails), loud. Severity: High, because it only happens for a part over 2 GiB, which needs a custom part size because the default part sizes come from the server's recommended size (about 100 MB), and there is no workaround besides smaller parts.

How to check

Found by reading the code, not reproduced. Read getRemaining and its callers. A unit test could wrap a stream in B2InputStreamExcerpt with a start of 0 and a length of 3 GiB and call read(buf, 0, 10). Clamping with (int) Math.min(Integer.MAX_VALUE, pastEnd - iPosition) would avoid the overflow.

Version

Seen at v6.5.0. Present on the default branch: present.

主要语言
Java
星标
103
派生
23
平均合并
5 天 8 小时
30 天内合并 PR
3

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Backblaze/b2-sdk-java 的其他 Issue

查看 Backblaze/b2-sdk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。