Skip to content

Reject negative zero ints in the pure Python binary reader - #452

Open
kwy404 wants to merge 1 commit into
amazon-ion:masterfrom
kwy404:fix-binary-negative-int-zero
Open

kwy404 wants to merge 1 commit into
amazon-ion:masterfrom
kwy404:fix-binary-negative-int-zero

Conversation

@kwy404

@kwy404 kwy404 commented Sep 26, 2026

Copy link
Copy Markdown

Issue #, if available: #119

Description of changes:

Root cause: in the pure Python binary reader, _int_factory returns sign * magnitude for a type code 3 (negative int) and never checks whether the magnitude is zero. So 0x31 0x00 (and 0x3E 0x81 0x00) loads as 0, although the spec says negative zero is illegal. ion-c already rejects it with IERR_INVALID_BINARY, so the result depended on which reader was used (the pure Python one runs when the C extension is not available, when simpleion.c_ext = False, or when a catalog is passed).

Fix: _int_factory now raises IonException when a negative int's magnitude bytes are all zero.

Test: added a NEGATIVE INT ZERO case to _BAD_VALUES in tests/test_reader_binary.py and removed bad/negativeIntZero.10n from the skip list in tests/test_vectors.py. Both fail before the change (DID NOT RAISE) and pass after it. The rest of the suite (without the benchmark tests) still passes: 29212 passed, 5 skipped.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

A binary int with type code 3 (negative) and a zero magnitude is
invalid Ion, but the pure Python reader returned it as 0. Raise
IonException instead, matching ion-c, and stop skipping the
bad/negativeIntZero.10n test vector.

Fixes amazon-ion#119
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.

1 participant