From cccd14559f980b4a293a6413bbab7749c062348b Mon Sep 17 00:00:00 2001 From: Tyler Gregg Date: Thu, 11 Apr 2024 17:12:06 -0700 Subject: [PATCH] Ensures that the cursor's value marker is fully reset between values. --- .../com/amazon/ion/impl/IonCursorBinary.java | 1 + ...onReaderContinuableTopLevelBinaryTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/amazon/ion/impl/IonCursorBinary.java b/src/main/java/com/amazon/ion/impl/IonCursorBinary.java index 7e06b6db4e..c426b813ec 100644 --- a/src/main/java/com/amazon/ion/impl/IonCursorBinary.java +++ b/src/main/java/com/amazon/ion/impl/IonCursorBinary.java @@ -1094,6 +1094,7 @@ private boolean checkContainerEnd() { * Resets state specific to the current value. */ private void reset() { + valueMarker.typeId = null; valueMarker.startIndex = -1; valueMarker.endIndex = -1; fieldSid = -1; diff --git a/src/test/java/com/amazon/ion/impl/IonReaderContinuableTopLevelBinaryTest.java b/src/test/java/com/amazon/ion/impl/IonReaderContinuableTopLevelBinaryTest.java index cb4d44ae34..a0720710c7 100644 --- a/src/test/java/com/amazon/ion/impl/IonReaderContinuableTopLevelBinaryTest.java +++ b/src/test/java/com/amazon/ion/impl/IonReaderContinuableTopLevelBinaryTest.java @@ -3933,6 +3933,25 @@ public void annotationSequenceLengthThatOverflowsBufferThrowsIonException(boolea ); } + @ParameterizedTest(name = "constructFromBytes={0}") + @ValueSource(booleans = {true, false}) + public void incompleteAnnotationAfterStructFailsCleanly(boolean constructFromBytes) throws Exception { + expectIonException( + constructFromBytes, + reader -> { + try { + assertEquals(IonType.STRUCT, reader.next()); + } catch (Exception e) { + fail(); + } + // This should fail with IonException due to unexpected EOF. + reader.next(); + }, + 0xDF, // null.struct + 0xE6, 0x81 // Incomplete annotation wrapper declaring length 6 + ); + } + /** * Verifies that corrupting each byte in the input data results in IonException, or nothing. * @param constructFromBytes whether to provide bytes (true) or an InputStream (false) to the reader.