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

Replace Assertion Failure with Error for Premature Container Ends #356

Merged
merged 2 commits into from
Jan 9, 2025
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
7 changes: 6 additions & 1 deletion 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 (preader->_depth > 0 && value_start < binary->_local_end) {
FAILWITH(IERR_EOF);
}
goto at_eof;
}

Expand Down Expand Up @@ -370,7 +373,9 @@ iERR _ion_reader_binary_step_out(ION_READER *preader)

if (curr_pos <= next_start) {
// if we're at EOF then we should be spot on (curr_pos == next_start)
ASSERT(preader->_eof ? (curr_pos == next_start) : (curr_pos <= next_start));
if (preader->_eof && curr_pos < next_start) {
FAILWITH(IERR_UNEXPECTED_EOF);
}
to_skip = next_start - curr_pos;
while (to_skip > 0) {
if (to_skip > MAX_SIZE) {
Expand Down
20 changes: 20 additions & 0 deletions test/test_ion_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,26 @@ TEST(IonBinaryBlob, CanFullyReadBlobUsingPartialReads) {
29, tid_BLOB, 23, "This is a BLOB of text.");
}

TEST(IonContainers, IncompleteContainerIsError) {
hREADER reader = NULL;
ION_TYPE type;

// 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_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));
}

// Simple test to ensure that if we supply a buffer size of 0 to ion_reader_read_lob_bytes, we don't assert. If the user
// is reading values via the LOB size, and does not specifically handle 0-lengthed LOBs the reader shouldn't fail.
TEST(IonBinaryBlob, CanReadZeroLength) {
Expand Down
Loading