Skip to content

Commit

Permalink
Fixes a bug that caused the binary reader to prematurely assume EOF h…
Browse files Browse the repository at this point in the history
…ad been reached in an e-expression.
  • Loading branch information
tgregg committed Oct 30, 2024
1 parent 383066b commit 69951dd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
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 @@ -2692,6 +2692,7 @@ void stepIntoEExpression() {
pushContainer();
parent.typeId = valueTid;
// TODO support length prefixed e-expressions.
// TODO when the length is known to be within the buffer, exit slow mode.
parent.endIndex = DELIMITED_MARKER;
valueTid = null;
event = Event.NEEDS_INSTRUCTION;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.amazon.ion.impl;

import com.amazon.ion.IonBufferConfiguration;
Expand Down Expand Up @@ -219,6 +218,9 @@ void prepareScalar() {
if (event == Event.NEEDS_INSTRUCTION) {
throw new OversizedValueException();
}
} else {
super.prepareScalar();
return;
}
}
throw new IonException("Unexpected EOF.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,4 +1079,22 @@ public void taglessCompactSymbols(boolean constructFromBytes) throws Exception {
);
}
}

@ParameterizedTest(name = "constructFromBytes={0}")
@ValueSource(booleans = {true, false})
public void addSymbolsSystemMacro(boolean constructFromBytes) throws Exception {
byte[] data = withIvm(1, bytes(
0xEF, 0x0C, // system macro add_symbols
0x02, // AEB: 0b------aa; a=10, expression group
0x01, // FlexInt 0, a delimited expression group
0x93, 0x61, 0x62, 0x63, // 3-byte string, utf-8 "abc"
0xF0, // delimited end... of expression group
0xE1, // SID single byte
0x42 // SID $66
));
try (IonReaderContinuableCoreBinary reader = initializeReader(constructFromBytes, data)) {
assertEquals(START_SCALAR, reader.nextValue());
assertEquals(66, reader.symbolValueId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5985,5 +5985,24 @@ private void invokeValuesUsingSystemMacroOpcodeHelper(boolean constructFromBytes
closeAndCount();
}

@ParameterizedTest(name = "constructFromBytes={0}")
@ValueSource(booleans = {true, false})
public void addSymbolsSystemMacro(boolean constructFromBytes) throws Exception {
int[] data = new int[] {
0xE0, 0x01, 0x01, 0xEA, // Ion 1.1 IVM
0xEF, 0x0C, // system macro add_symbols
0x02, // AEB: 0b------aa; a=10, expression group
0x01, // FlexInt 0, a delimited expression group
0x93, 0x61, 0x62, 0x63, // 3-byte string, utf-8 "abc"
0xF0, // delimited end... of expression group
0xE1, // SID single byte
0x42 // SID $66
};
try (IonReader reader = readerFor(constructFromBytes,data)) {
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
}
}

// TODO Ion 1.1 symbol tables with all kinds of annotation encodings (opcodes E4 - E9, inline and SID)
}

0 comments on commit 69951dd

Please sign in to comment.