Skip to content

Commit

Permalink
Adjust ASSERTs so users can read lobs with a zero-size buffer length …
Browse files Browse the repository at this point in the history
…and not fault
  • Loading branch information
nirosys committed Aug 5, 2024
1 parent a975b45 commit 928ccf7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ionc/ion_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ iERR _ion_reader_read_lob_bytes_helper(ION_READER *preader, BOOL accept_partial,

ASSERT(preader);
ASSERT(p_buf);
ASSERT(buf_max);
ASSERT(buf_max >= 0);
ASSERT(p_length);

switch(preader->type) {
Expand Down
2 changes: 1 addition & 1 deletion ionc/ion_reader_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ iERR _ion_reader_text_read_lob_bytes(ION_READER *preader, BOOL accept_partial, B

ASSERT(preader);
ASSERT(p_buf);
ASSERT(buf_max);
ASSERT(buf_max >= 0);
ASSERT(p_length);

if (text->_state == IPS_ERROR
Expand Down
21 changes: 21 additions & 0 deletions test/test_ion_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,27 @@ TEST(IonBinaryBlob, CanFullyReadBlobUsingPartialReads) {
29, tid_BLOB, 23, "This is a BLOB of text.");
}

// 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, CanReadZeroLengthBlobWithLobLength) {
hREADER reader;
ION_TYPE type;
const char *buffer = "\xE0\x01\x00\xEA\xA0";
char bytes[1]; // Shouldn't write any..

SIZE lob_size, bytes_read;
ION_ASSERT_OK(ion_reader_open_buffer(&reader, (BYTE*)buffer, 5, NULL));

ION_ASSERT_OK(ion_reader_next(reader, &type));
ASSERT_EQ(tid_BLOB, type);
ION_ASSERT_OK(ion_reader_get_lob_size(reader, &lob_size));
ASSERT_EQ(0, lob_size);
ION_ASSERT_OK(ion_reader_read_lob_bytes(reader, (BYTE*)bytes, lob_size, &bytes_read));
ASSERT_EQ(0, bytes_read);

ION_ASSERT_OK(ion_reader_close(reader));
}

void test_ion_binary_writer_supports_32_bit_floats(float value, const char *expected, SIZE expected_len) {
hWRITER writer = NULL;
ION_STREAM *ion_stream = NULL;
Expand Down

0 comments on commit 928ccf7

Please sign in to comment.