Skip to content

fix: reject out-of-range integral cell values - #1101

Merged
delei merged 4 commits into
apache:mainfrom
nkuprins:fix/integral-number-overflow
Oct 8, 2026
Merged

delei merged 4 commits into
apache:mainfrom
nkuprins:fix/integral-number-overflow

Conversation

@nkuprins

Copy link
Copy Markdown
Contributor

Closed: #1100

Purpose of the pull request

As title.

What's changed?

  • Integer converters and NumberUtils.parseByte/parseShort/parseInteger/parseLong now range-check the value before narrowing, so out-of-range values throw instead of wrapping around.
  • The integer parse* methods now call parseBigDecimal, which already has the hasFormat branch.
  • Added out-of-range tests to ConverterTest and NumberUtilsTest.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@nkuprins
nkuprins marked this pull request as ready for review September 15, 2026 08:36

@skytin1004 skytin1004 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I reproduced the issue on main and verified the fix for XLSX, XLS, and CSV. LGTM.

@BigDataDZ

Copy link
Copy Markdown
Contributor

Reviewed the diff - the approach looks right: checkRange truncates toward zero first (so fractional values keep narrowing the way they did before intValueExact-style strictness would allow) and only the truncated integral part is range-checked, which matches the semantics I had implemented in the now-closed #1188.

One suggestion: add a fraction-truncation regression test (e.g. parseInteger("123.9") == 123 and the same for a NUMBER cell on IntegerNumberConverter). Nothing in the current tests pins that behavior, and it protects the narrowing semantics from being "exactified" by a future refactor.

@nkuprins

nkuprins commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Reviewed the diff - the approach looks right: checkRange truncates toward zero first (so fractional values keep narrowing the way they did before intValueExact-style strictness would allow) and only the truncated integral part is range-checked, which matches the semantics I had implemented in the now-closed #1188.

One suggestion: add a fraction-truncation regression test (e.g. parseInteger("123.9") == 123 and the same for a NUMBER cell on IntegerNumberConverter). Nothing in the current tests pins that behavior, and it protects the narrowing semantics from being "exactified" by a future refactor.

Thanks, the fraction case is already pinned: test_parseInteger_noFormat_truncatesFraction and the 42.9 assertion in ConverterTest cover it, and test_toInt_bounds covers the 2147483647.9 / -2147483648.9 boundary that a stricter refactor would break. I'd rather not add a near-duplicate 123.9 test.

@delei delei left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The range checks make the parsing behavior much safer and more predictable.

@delei
delei merged commit 9f98054 into apache:main Oct 8, 2026
9 checks passed
@nkuprins
nkuprins deleted the fix/integral-number-overflow branch October 8, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Integer, Long, Short and Byte fields return wrong values when a cell is out of range

4 participants