Repository navigation
Reject symbol IDs and VarInts that overflow int in the binary reader - #1173
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1173 +/- ##
============================================
+ Coverage 67.23% 68.40% +1.17%
- Complexity 5484 5768 +284
============================================
Files 159 160 +1
Lines 23025 23543 +518
Branches 4126 4251 +125
============================================
+ Hits 15481 16105 +624
+ Misses 6262 6134 -128
- Partials 1282 1304 +22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tgregg
reviewed
Dec 3, 2026
tgregg
left a comment
Contributor
There was a problem hiding this comment.
-2^31 and only round tripped because the reader overflowed the same way. That encoding now fails to read back. I kept this change on the read side, but can fold the writer fix in here if you would rather have both together.
Yes, it would be great to include the write side fix here too.
…in the binary writer - symbolValueId now skips leading zero bytes before checking that the symbol ID fits in an int, so zero-padded IDs that fit are accepted. - IonRawBinaryWriter computes the decimal (and fractional second) exponent as -(long) scale, so a scale of Integer.MIN_VALUE is written as exponent 2^31 rather than overflowing to -2^31. Co-authored-by: Radhika <radhika@research.itecz.au>
IonDatagram.getBytes() negated the decimal scale in int arithmetic, and writeVarInt(int) mis-encoded Integer.MIN_VALUE as -0. A BigDecimal with scale Integer.MIN_VALUE was therefore silently written as exponent -0 (e.g. 1d2147483648 round tripped as 1d0). The exponent is now computed as a long and writeVarInt accepts a long magnitude up to 2^31. Co-authored-by: Radhika <radhika@research.itecz.au>
NovemberZulu
approved these changes
Dec 4, 2026
NovemberZulu
left a comment
Collaborator
There was a problem hiding this comment.
Unhugged else feels lonely
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.
Issue #, if available: n/a
Description of changes:
The Ion 1.0 binary reader decodes VarUInt and VarInt sub-fields into a Java
intwithout checking that they fit, and narrows field name and symbol value IDs fromlongwith a plain cast. A 5-byte VarUInt of 2^32 + 4 wraps to 4, so an out-of-range symbol ID used as a field name, annotation or symbol value resolves to$4(name) instead of failing the wayfieldNameSymbolIDUnmapped.10nandannotationSymbolIDUnmapped.10nin ion-tests require. The same wrap turns a timestamp year of 2^32 + 2000 into2000T, and a decimal exponent of 2^31 + 1 into -(2^31 - 1), so1d2147483649reads back as1d-2147483647. Two Ion implementations can end up disagreeing about the contents of the same document.Reproducer for the field name case (the others are covered by the new tests):
Before:
{name: 1}. After:IonException: Found a symbol ID that was too large to fit in an int.The checks live in the sub-field readers so that every caller (field names, annotations, symbol values, timestamp fields, decimal exponents) is covered in one place:
readVarUInt_1_0bounds its accumulator,readVarInt_1_0accumulates in alongwith a 2^31 magnitude bound and the decimal scale and timestamp offset are range checked before narrowing, andIonCursorBinary.symbolIdToIntrejects symbol IDs outside theintrange. The VarInt bound still admits an exponent of exactly 2^31, so aBigDecimalwith scaleInteger.MIN_VALUEremains readable.One side effect worth a look:
IonRawBinaryWriter.writeDecimalValuecomputes the exponent as-value.scale()inintarithmetic, so a scale ofInteger.MIN_VALUEis written as exponent -2^31 and only round tripped because the reader overflowed the same way. That encoding now fails to read back. I kept this change on the read side, but can fold the writer fix in here if you would rather have both together.Regression tests were added to
IonReaderContinuableCoreBinaryTestandIonReaderContinuableTopLevelBinaryTest;./gradlew buildandminifyTest21pass locally.