ion-c icon indicating copy to clipboard operation
ion-c copied to clipboard

Ion binary reader reads null symbol will cause invalid state failure.

Open cheqianh opened this issue 4 years ago • 1 comments

When we use the binary reader to read a NULL symbol and then call the ion_reader_read_null api, it will fail with IERR_INVALID_STATE.

cheqianh avatar Jan 20 '21 00:01 cheqianh

// reproduction for amzn/ion-c#223
TEST(IonBinarySymbol, BinarySymbolIsNullAfterReadNext) {

    // Wrtie binary $0
    hWRITER writer = NULL;
    ION_STREAM *ion_stream = NULL;
    BYTE *data;
    SIZE data_length;
    BOOL is_binary = true;

    ION_ASSERT_OK(ion_test_new_writer(&writer, &ion_stream, is_binary));
    ION_ASSERT_OK(_ion_writer_binary_write_symbol_id(writer, 0));
    ION_ASSERT_OK(ion_test_writer_get_bytes(writer, ion_stream, &data, &data_length));

    // Read

    hREADER reader = NULL;
    ION_TYPE type;
    ION_TYPE null_type;

    ION_ASSERT_OK(ion_test_new_reader(data, data_length, &reader));

    ION_ASSERT_OK(ion_reader_next(reader, &type));
    
    ION_ASSERT_OK(ion_reader_read_null(reader, &null_type));
    ION_ASSERT_OK(ion_reader_close(reader));
}

cheqianh avatar May 12 '21 17:05 cheqianh