Skip to content

Commit

Permalink
Ensures that the cursor's value marker is fully reset between values.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgregg committed Apr 12, 2024
1 parent 409987b commit cccd145
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/amazon/ion/impl/IonCursorBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cccd145

Please sign in to comment.