Guard HDGF PointerFactory offset/length uint32 narrowing#1076
Merged
pjfanning merged 3 commits intoMay 15, 2026
Conversation
pjfanning
reviewed
May 15, 2026
| // would silently wrap to a negative int rather than letting the wrapped | ||
| // value reach the downstream IOUtils.safelyClone bounds check. | ||
| p.setOffset(Math.toIntExact(LittleEndian.getUInt(data, offset+8))); | ||
| p.setLength(Math.toIntExact(LittleEndian.getUInt(data, offset+12))); |
Member
There was a problem hiding this comment.
any chance that you could get these values as longs and then call the check methods on IOUtils? At least for length. The exception messages thrown by IOUtils are more informative than 'int overflow'.
Contributor
Author
There was a problem hiding this comment.
Done both fields are now read as long up-front.
Length goes through IOUtils.safelyAllocateCheck(value, Integer.MAX_VALUE); Offset has a small helper throwing RecordFormatException with the offending value
Tests and poi-integration-exceptions.csv updated to match the new exception.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace unchecked uint32-to-int narrowing in HDGF PointerFactory for offset and length fields with Math.toIntExact.
These values originate from LittleEndian.getUInt(...) and later flow into stream offset/length arithmetic and StreamStore construction. Malformed values above Integer.MAX_VALUE could previously wrap into negative or truncated integers.
This change aligns PointerFactory with the HDGF ChunkHeader hardening introduced in PR #1075 and with the broader parser hardening work using Math.toIntExact for structural size and offset fields.
Address parsing intentionally remains unchanged because the value is only used for diagnostic/debug output and does not participate in bounds calculations.
Added regression tests covering: