From 61be041f84e0119b063857cf095e1a1beaead7a9 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sat, 27 Apr 2024 15:08:29 +0300 Subject: [PATCH] Tests: test_index: Test that *i = NULL is done on LZMA_PROG_ERROR On LZMA_DATA_ERROR from lzma_index_buffer_decode(), *i = NULL was already done but this adds a test for that case too. (cherry picked from commit 575b11b0d291e66c5fce31ce7a72f11436d57c83) --- tests/test_index.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/test_index.c b/tests/test_index.c index 673186c5..9e3e5fc2 100644 --- a/tests/test_index.c +++ b/tests/test_index.c @@ -1529,11 +1529,21 @@ test_lzma_index_decoder(void) LZMA_PROG_ERROR); assert_lzma_ret(lzma_index_decoder(&strm, NULL, MEMLIMIT), LZMA_PROG_ERROR); - assert_lzma_ret(lzma_index_decoder(NULL, &decode_test_index, - MEMLIMIT), LZMA_PROG_ERROR); + + // If the first argument (lzma_stream *strm) is NULL then + // *idx must still become NULL since the API docs say that + // it's done if an error occurs. This was fixed in + // 71eed2520e2eecae89bade9dceea16e56cfa2ea0. + lzma_index *idx_allocated = lzma_index_init(NULL); + lzma_index *idx = idx_allocated; + assert_lzma_ret(lzma_index_decoder(NULL, &idx, MEMLIMIT), + LZMA_PROG_ERROR); + assert_true(idx == NULL); + + lzma_index_end(idx_allocated, NULL); + idx_allocated = NULL; // Do actual decode - lzma_index *idx; assert_lzma_ret(lzma_index_decoder(&strm, &idx, MEMLIMIT), LZMA_OK); @@ -1659,24 +1669,37 @@ test_lzma_index_buffer_decode(void) assert_lzma_ret(lzma_index_buffer_decode(NULL, NULL, NULL, NULL, NULL, 0), LZMA_PROG_ERROR); - lzma_index *idx; uint64_t memlimit = MEMLIMIT; size_t in_pos = 0; + lzma_index *idx_allocated = lzma_index_init(NULL); + lzma_index *idx = idx_allocated; assert_lzma_ret(lzma_index_buffer_decode(&idx, NULL, NULL, NULL, NULL, 0), LZMA_PROG_ERROR); + assert_true(idx == NULL); + idx = idx_allocated; assert_lzma_ret(lzma_index_buffer_decode(&idx, &memlimit, NULL, NULL, NULL, 0), LZMA_PROG_ERROR); + assert_true(idx == NULL); + idx = idx_allocated; assert_lzma_ret(lzma_index_buffer_decode(&idx, &memlimit, NULL, decode_buffer, NULL, 0), LZMA_PROG_ERROR); + assert_true(idx == NULL); + idx = idx_allocated; assert_lzma_ret(lzma_index_buffer_decode(&idx, &memlimit, NULL, decode_buffer, NULL, 0), LZMA_PROG_ERROR); + assert_true(idx == NULL); + idx = idx_allocated; assert_lzma_ret(lzma_index_buffer_decode(&idx, &memlimit, NULL, decode_buffer, &in_pos, 0), LZMA_DATA_ERROR); + assert_true(idx == NULL); + + lzma_index_end(idx_allocated, NULL); + idx_allocated = NULL; in_pos = 1; assert_lzma_ret(lzma_index_buffer_decode(&idx, &memlimit, NULL,