Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a bug that caused the binary reader to prematurely assume EOF had been reached in an e-expression. #982

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading