B2ByteRange.parse throws NumberFormatException for numbers beyond long range

Open Beginner friendly
#245 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Start in core/src/main/java/com/backblaze/b2/util/B2ByteRange.java: the digit pattern is near line 29, parse is at lines 56-60, and longOrNullFromStr at lines 143-149 calls Long.valueOf. Confirm by reading that a long-overflowing digit run throws NumberFormatException, then catch it in the helper so parse returns null as its javadoc says. Done when B2ByteRange.parse("bytes=99999999999999999999-") returns null and a unit test for that input passes.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
103
Forks
23
Avg merge
5d 8h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Backblaze/b2-sdk-java

All issues in Backblaze/b2-sdk-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.