|
3 | 3 |
|
4 | 4 | package com.amazon.ion.impl;
|
5 | 5 |
|
| 6 | +import com.amazon.ion.IonCursor; |
6 | 7 | import com.amazon.ion.IonException;
|
7 | 8 | import com.amazon.ion.IonType;
|
8 | 9 | import org.junit.jupiter.api.Test;
|
@@ -496,4 +497,56 @@ public void expectLobWithOverflowingEndIndexToFailCleanly(boolean constructFromB
|
496 | 497 | assertThrows(IonException.class, reader::nextValue);
|
497 | 498 | reader.close();
|
498 | 499 | }
|
| 500 | + |
| 501 | + @Test |
| 502 | + public void expectIncompleteContainerToFailCleanlyAfterFieldSid() { |
| 503 | + IonReaderContinuableCoreBinary reader = initializeReader( |
| 504 | + true, |
| 505 | + 0xE0, 0x01, 0x00, 0xEA, // IVM |
| 506 | + 0xDC, // Struct, length 12 |
| 507 | + 0x9A // Field SID 26 |
| 508 | + // The struct ends unexpectedly |
| 509 | + ); |
| 510 | + assertEquals(IonCursor.Event.START_CONTAINER, reader.nextValue()); |
| 511 | + assertEquals(IonType.STRUCT, reader.getType()); |
| 512 | + reader.stepIntoContainer(); |
| 513 | + // This is an unexpected EOF, so the reader should fail cleanly. |
| 514 | + assertThrows(IonException.class, reader::nextValue); |
| 515 | + reader.close(); |
| 516 | + } |
| 517 | + |
| 518 | + @Test |
| 519 | + public void expectIncompleteContainerToFailCleanlyAfterAnnotationHeader() { |
| 520 | + IonReaderContinuableCoreBinary reader = initializeReader( |
| 521 | + true, |
| 522 | + 0xE0, 0x01, 0x00, 0xEA, // IVM |
| 523 | + 0xDC, // Struct, length 12 |
| 524 | + 0x9A, // Field SID 26 |
| 525 | + 0xE4, // Annotation wrapper length 4 |
| 526 | + 0x00, 0x81, // VarUInt length 1 (overpadded by 1 byte) |
| 527 | + 0x00, 0x84 // VarUInt SID 4 (overpadded by 1 byte) |
| 528 | + // The value ends unexpectedly |
| 529 | + ); |
| 530 | + assertEquals(IonCursor.Event.START_CONTAINER, reader.nextValue()); |
| 531 | + assertEquals(IonType.STRUCT, reader.getType()); |
| 532 | + reader.stepIntoContainer(); |
| 533 | + // This is an unexpected EOF, so the reader should fail cleanly. |
| 534 | + assertThrows(IonException.class, reader::nextValue); |
| 535 | + reader.close(); |
| 536 | + } |
| 537 | + |
| 538 | + @Test |
| 539 | + public void expectIncompleteAnnotationHeaderToFailCleanly() { |
| 540 | + IonReaderContinuableCoreBinary reader = initializeReader( |
| 541 | + true, |
| 542 | + 0xE0, 0x01, 0x00, 0xEA, // IVM |
| 543 | + 0xE4, // Annotation wrapper length 5 |
| 544 | + 0x81, // VarUInt length 1 |
| 545 | + 0x84 // VarUInt SID 4 |
| 546 | + // The value ends unexpectedly |
| 547 | + ); |
| 548 | + // This is an unexpected EOF, so the reader should fail cleanly. |
| 549 | + assertThrows(IonException.class, reader::nextValue); |
| 550 | + reader.close(); |
| 551 | + } |
499 | 552 | }
|
0 commit comments