Skip to content

Commit

Permalink
Add check for valid state in reader next as well
Browse files Browse the repository at this point in the history
I realized the text reader also throws an error when the user tries
to get the next value from within the container. That seems right
to me as well, so I added a check there and then a test to prove
consistency.
  • Loading branch information
rmarrowstone committed Jan 7, 2025
1 parent 9801437 commit e5e5f1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ionc/ion_reader_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ iERR _ion_reader_binary_next(ION_READER *preader, ION_TYPE *p_value_type)
value_start = ion_stream_get_position(preader->istream); // the field name isn't part of the value
ION_GET(preader->istream, type_desc_byte); // read the TID byte
if (type_desc_byte == EOF) {
if (value_start < binary->_local_end) {
FAILWITH(IERR_EOF);
}
goto at_eof;
}

Expand Down
12 changes: 10 additions & 2 deletions test/test_ion_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,20 @@ TEST(IonBinaryBlob, CanFullyReadBlobUsingPartialReads) {
TEST(IonContainers, IncompleteContainerIsError) {
hREADER reader = NULL;
ION_TYPE type;
ION_ASSERT_OK(ion_test_new_reader((BYTE*)"\xE0\x01\x00\xEA\xB6", 5, &reader));

// runs same steps against text to prove consistency
ION_ASSERT_OK(ion_test_new_reader((BYTE*)"[", 1, &reader));
ION_ASSERT_OK(ion_reader_next(reader, &type));
ASSERT_EQ(tid_LIST, type);
ION_ASSERT_OK(ion_reader_step_in(reader));
ION_ASSERT_FAIL(ion_reader_next(reader, &type));
ION_ASSERT_FAIL(ion_reader_step_out(reader));

ION_ASSERT_OK(ion_test_new_reader((BYTE*)"\xE0\x01\x00\xEA\xB2", 5, &reader));
ION_ASSERT_OK(ion_reader_next(reader, &type));
ASSERT_EQ(tid_EOF, type);
ASSERT_EQ(tid_LIST, type);
ION_ASSERT_OK(ion_reader_step_in(reader));
ION_ASSERT_FAIL(ion_reader_next(reader, &type));
ION_ASSERT_FAIL(ion_reader_step_out(reader));
}

Expand Down

0 comments on commit e5e5f1e

Please sign in to comment.