Skip to content

Commit 676455a

Browse files
committed
Fixes Ion Binary Reader to fail fast when an IVM type code is encountered in an illegal position
1 parent ac594ac commit 676455a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ion-tests

src/com/amazon/ion/impl/IonReaderBinaryRawX.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ private final void has_next_helper_raw() throws IOException
283283
else if (_value_tid == _Private_IonConstants.tidTypedecl) {
284284
assert (_value_tid == (BINARY_VERSION_MARKER_TID & 0xff)); // the bvm tid happens to be type decl
285285
if (_value_len == BINARY_VERSION_MARKER_LEN ) {
286+
if (getDepth() != 0) {
287+
// In Ion text, we can interpret an IVM in the wrong position as an ordinary Symbol,
288+
// but in Ion binary, the BVM is unambiguously an IVM rather than a Symbol, and it
289+
// is not allowed in any container type.
290+
throw newErrorAt("Encountered IVM type code E0 below the top level");
291+
}
286292
// this isn't valid for any type descriptor except the first byte
287293
// of a 4 byte version marker - so lets read the rest
288294
load_version_marker();

0 commit comments

Comments
 (0)