B2ByteRange.parse throws NumberFormatException for numbers beyond long range

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

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

从 core/src/main/java/com/backblaze/b2/util/B2ByteRange.java 开始:数字模式位于第 29 行附近,parse 位于第 56-60 行,而第 143-149 行的 longOrNullFromStr 调用了 Long.valueOf。通过阅读代码确认,溢出 long 的数字串会抛出 NumberFormatException,然后在辅助方法中捕获它,使 parse 按其 javadoc 所述返回 null。当 B2ByteRange.parse("bytes=99999999999999999999-") 返回 null,且针对该输入的单元测试通过时,即为完成。

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

描述

What happens

The javadoc says B2ByteRange.parse returns null on error. The pattern accepts any run of digits, then Long.valueOf throws NumberFormatException for a number that does not fit in a long, for example bytes=99999999999999999999-. The exception escapes parse instead of the documented null.

Where

core/src/main/java/com/backblaze/b2/util/B2ByteRange.java:29 (the pattern), :56-60 (parse, documented to return null on error) and :143-149 (longOrNullFromStr, which calls Long.valueOf).

Why it matters

Impact: Wrong request or result (documented null return becomes an exception), loud. Severity: Medium, because it needs an out-of-range number in the input (unusual), and a caller can work around it by catching NumberFormatException.

How to check

Found by reading the code, not reproduced. Call B2ByteRange.parse("bytes=99999999999999999999-"): by reading, Long.valueOf throws. Catching NumberFormatException in longOrNullFromStr/parse and returning null would match the documentation.

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 摘要。