From f278bb473e1f92de6ddd5e7284bd2a9771564f9b Mon Sep 17 00:00:00 2001 From: kwy404 Date: Sat, 26 Sep 2026 05:40:34 -0300 Subject: [PATCH] Reject negative zero ints in the pure Python binary reader 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 #119 --- src-python/amazon/ion/reader_binary.py | 3 +++ tests/test_reader_binary.py | 2 ++ tests/test_vectors.py | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src-python/amazon/ion/reader_binary.py b/src-python/amazon/ion/reader_binary.py index 6b5d8d5d3..7447a355f 100644 --- a/src-python/amazon/ion/reader_binary.py +++ b/src-python/amazon/ion/reader_binary.py @@ -494,6 +494,9 @@ def _rslice(data, rem, size): def _int_factory(sign, data): + if sign < 0 and not any(data): + raise IonException('Negative zero is not a valid int.') + def parse_int(): value = 0 length = len(data) diff --git a/tests/test_reader_binary.py b/tests/test_reader_binary.py index f92f85aec..f36baa690 100644 --- a/tests/test_reader_binary.py +++ b/tests/test_reader_binary.py @@ -117,6 +117,8 @@ def _prepend_ivm(params): (b'\xe4\x81\x84\xb2\x21\x01', 'ANNOT LENGTH TOO SHORT - CONTAINER'), # The annotation wrapper declares 3 octets, but the subfields (including an int) take up four. (b'\xe3\x81\x84\x21\x01', 'ANNOT LENGTH TOO SHORT - SCALAR'), + # A negative int with a magnitude of zero (negative zero) is illegal. + (b'\x31\x00', 'NEGATIVE INT ZERO'), # TODO: annnotated nop is a fail # TODO: value within container is longer than container. diff --git a/tests/test_vectors.py b/tests/test_vectors.py index 431a4f91c..9b98e708d 100644 --- a/tests/test_vectors.py +++ b/tests/test_vectors.py @@ -113,7 +113,6 @@ def _open(file): _bad_file(u'localSymbolTableWithMultipleImportsFields.10n'), # TODO amazon-ion/ion-python#118 _bad_file(u'localSymbolTableWithMultipleSymbolsAndImportsFields.10n'), # TODO amazon-ion/ion-python#118 _bad_file(u'localSymbolTableWithMultipleSymbolsFields.10n'), # TODO amazon-ion/ion-python#118 - _bad_file(u'negativeIntZero.10n'), # TODO amazon-ion/ion-python#119 _equivs_file(u'timestampSuperfluousOffset.10n') # TODO amazon-ion/ion-python#121 )