diff --git a/ionc/ion_reader.c b/ionc/ion_reader.c index b791f69..d8b5ec3 100644 --- a/ionc/ion_reader.c +++ b/ionc/ion_reader.c @@ -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) { diff --git a/ionc/ion_reader_text.c b/ionc/ion_reader_text.c index 8b7b106..a5278e5 100644 --- a/ionc/ion_reader_text.c +++ b/ionc/ion_reader_text.c @@ -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 diff --git a/test/test_ion_binary.cpp b/test/test_ion_binary.cpp index b1c6c41..a9b2ec3 100644 --- a/test/test_ion_binary.cpp +++ b/test/test_ion_binary.cpp @@ -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;