diff options
Diffstat (limited to 'tests')
49 files changed, 37 insertions, 33 deletions
diff --git a/tests/files/README b/tests/files/README index 9818d3f1..8f0a73a7 100644 --- a/tests/files/README +++ b/tests/files/README @@ -172,11 +172,14 @@ bad-1-block_header-3.xz has wrong CRC32 in Block Header. - bad-1-block_header-4.xz has too big Compressed Size (2^63 bytes while - maximum is 2^63 - 4 bytes) in Block Header. It's important that the - file gets rejected due to invalid Compressed Size value; the decoder + bad-1-block_header-4.xz has too big Compressed Size in Block Header + (2^64 - 1 bytes while maximum is a little less, because the whole + Block must stay smaller than 2^64). It's important that the file + gets rejected due to invalid Compressed Size value; the decoder must not try decoding the Compressed Data field. + bad-1-block_header-5.xz has zero as Compressed Size in Block Header. + bad-2-index-1.xz has wrong Total Sizes in Index. bad-2-index-2.xz has wrong Uncompressed Sizes in Index. @@ -185,6 +188,9 @@ bad-2-index-4.xz wrong CRC32 in Index. + bad-2-index-5.xz has zero as Total Size. It is important that the file + gets rejected specifically due to Total Size having an invalid value. + bad-2-compressed_data_padding.xz has non-nul byte in the padding of the Compressed Data field of the first Block. diff --git a/tests/files/bad-1-block_header-1.xz b/tests/files/bad-1-block_header-1.xz Binary files differindex e126a419..d991536a 100644 --- a/tests/files/bad-1-block_header-1.xz +++ b/tests/files/bad-1-block_header-1.xz diff --git a/tests/files/bad-1-block_header-2.xz b/tests/files/bad-1-block_header-2.xz Binary files differindex e3e8166d..ae42ecf0 100644 --- a/tests/files/bad-1-block_header-2.xz +++ b/tests/files/bad-1-block_header-2.xz diff --git a/tests/files/bad-1-block_header-3.xz b/tests/files/bad-1-block_header-3.xz Binary files differindex 17955038..606cbd20 100644 --- a/tests/files/bad-1-block_header-3.xz +++ b/tests/files/bad-1-block_header-3.xz diff --git a/tests/files/bad-1-block_header-4.xz b/tests/files/bad-1-block_header-4.xz Binary files differindex be31ce04..e72dfbfc 100644 --- a/tests/files/bad-1-block_header-4.xz +++ b/tests/files/bad-1-block_header-4.xz diff --git a/tests/files/bad-1-block_header-5.xz b/tests/files/bad-1-block_header-5.xz Binary files differnew file mode 100644 index 00000000..96521129 --- /dev/null +++ b/tests/files/bad-1-block_header-5.xz diff --git a/tests/files/bad-1-check-crc32.xz b/tests/files/bad-1-check-crc32.xz Binary files differindex f8ec7d61..1ebe1310 100644 --- a/tests/files/bad-1-check-crc32.xz +++ b/tests/files/bad-1-check-crc32.xz diff --git a/tests/files/bad-1-check-crc64.xz b/tests/files/bad-1-check-crc64.xz Binary files differindex eb406ce6..cdb77093 100644 --- a/tests/files/bad-1-check-crc64.xz +++ b/tests/files/bad-1-check-crc64.xz diff --git a/tests/files/bad-1-check-sha256.xz b/tests/files/bad-1-check-sha256.xz Binary files differindex e33cee80..def7bff1 100644 --- a/tests/files/bad-1-check-sha256.xz +++ b/tests/files/bad-1-check-sha256.xz diff --git a/tests/files/bad-1-lzma2-1.xz b/tests/files/bad-1-lzma2-1.xz Binary files differindex f7ff6dd3..640f592e 100644 --- a/tests/files/bad-1-lzma2-1.xz +++ b/tests/files/bad-1-lzma2-1.xz diff --git a/tests/files/bad-1-lzma2-2.xz b/tests/files/bad-1-lzma2-2.xz Binary files differindex 3b279195..69ab07d4 100644 --- a/tests/files/bad-1-lzma2-2.xz +++ b/tests/files/bad-1-lzma2-2.xz diff --git a/tests/files/bad-1-lzma2-3.xz b/tests/files/bad-1-lzma2-3.xz Binary files differindex e1a20831..66f48c5d 100644 --- a/tests/files/bad-1-lzma2-3.xz +++ b/tests/files/bad-1-lzma2-3.xz diff --git a/tests/files/bad-1-lzma2-4.xz b/tests/files/bad-1-lzma2-4.xz Binary files differindex e0eb7aaa..ac970419 100644 --- a/tests/files/bad-1-lzma2-4.xz +++ b/tests/files/bad-1-lzma2-4.xz diff --git a/tests/files/bad-1-lzma2-5.xz b/tests/files/bad-1-lzma2-5.xz Binary files differindex 437aeed0..700464d5 100644 --- a/tests/files/bad-1-lzma2-5.xz +++ b/tests/files/bad-1-lzma2-5.xz diff --git a/tests/files/bad-1-lzma2-6.xz b/tests/files/bad-1-lzma2-6.xz Binary files differindex f87cab68..2bda0c4b 100644 --- a/tests/files/bad-1-lzma2-6.xz +++ b/tests/files/bad-1-lzma2-6.xz diff --git a/tests/files/bad-1-lzma2-7.xz b/tests/files/bad-1-lzma2-7.xz Binary files differindex 1a487ca7..8cc711c1 100644 --- a/tests/files/bad-1-lzma2-7.xz +++ b/tests/files/bad-1-lzma2-7.xz diff --git a/tests/files/bad-1-stream_flags-1.xz b/tests/files/bad-1-stream_flags-1.xz Binary files differindex fd77d474..6511773e 100644 --- a/tests/files/bad-1-stream_flags-1.xz +++ b/tests/files/bad-1-stream_flags-1.xz diff --git a/tests/files/bad-1-stream_flags-2.xz b/tests/files/bad-1-stream_flags-2.xz Binary files differindex a4a582ad..0c66b364 100644 --- a/tests/files/bad-1-stream_flags-2.xz +++ b/tests/files/bad-1-stream_flags-2.xz diff --git a/tests/files/bad-1-stream_flags-3.xz b/tests/files/bad-1-stream_flags-3.xz Binary files differindex f10b8d00..a9b1f983 100644 --- a/tests/files/bad-1-stream_flags-3.xz +++ b/tests/files/bad-1-stream_flags-3.xz diff --git a/tests/files/bad-1-vli-1.xz b/tests/files/bad-1-vli-1.xz Binary files differindex e2a08b9e..6514ab12 100644 --- a/tests/files/bad-1-vli-1.xz +++ b/tests/files/bad-1-vli-1.xz diff --git a/tests/files/bad-1-vli-2.xz b/tests/files/bad-1-vli-2.xz Binary files differindex 604e8186..c16941b4 100644 --- a/tests/files/bad-1-vli-2.xz +++ b/tests/files/bad-1-vli-2.xz diff --git a/tests/files/bad-2-compressed_data_padding.xz b/tests/files/bad-2-compressed_data_padding.xz Binary files differindex 1d0f58b7..382d0476 100644 --- a/tests/files/bad-2-compressed_data_padding.xz +++ b/tests/files/bad-2-compressed_data_padding.xz diff --git a/tests/files/bad-2-index-1.xz b/tests/files/bad-2-index-1.xz Binary files differindex 42efda0d..f51ed214 100644 --- a/tests/files/bad-2-index-1.xz +++ b/tests/files/bad-2-index-1.xz diff --git a/tests/files/bad-2-index-2.xz b/tests/files/bad-2-index-2.xz Binary files differindex ee5e89c2..d7d00ff3 100644 --- a/tests/files/bad-2-index-2.xz +++ b/tests/files/bad-2-index-2.xz diff --git a/tests/files/bad-2-index-3.xz b/tests/files/bad-2-index-3.xz Binary files differindex f51eaad8..62428b87 100644 --- a/tests/files/bad-2-index-3.xz +++ b/tests/files/bad-2-index-3.xz diff --git a/tests/files/bad-2-index-4.xz b/tests/files/bad-2-index-4.xz Binary files differindex 1b5b78e4..9cf2df65 100644 --- a/tests/files/bad-2-index-4.xz +++ b/tests/files/bad-2-index-4.xz diff --git a/tests/files/bad-2-index-5.xz b/tests/files/bad-2-index-5.xz Binary files differnew file mode 100644 index 00000000..0a792709 --- /dev/null +++ b/tests/files/bad-2-index-5.xz diff --git a/tests/files/good-1-3delta-lzma2.xz b/tests/files/good-1-3delta-lzma2.xz Binary files differindex 3edb4805..a0be1d00 100644 --- a/tests/files/good-1-3delta-lzma2.xz +++ b/tests/files/good-1-3delta-lzma2.xz diff --git a/tests/files/good-1-block_header-1.xz b/tests/files/good-1-block_header-1.xz Binary files differindex c0cc7200..fea5ad2f 100644 --- a/tests/files/good-1-block_header-1.xz +++ b/tests/files/good-1-block_header-1.xz diff --git a/tests/files/good-1-block_header-2.xz b/tests/files/good-1-block_header-2.xz Binary files differindex 5eb8575c..6b5dcb34 100644 --- a/tests/files/good-1-block_header-2.xz +++ b/tests/files/good-1-block_header-2.xz diff --git a/tests/files/good-1-block_header-3.xz b/tests/files/good-1-block_header-3.xz Binary files differindex 5e8dc78b..15653120 100644 --- a/tests/files/good-1-block_header-3.xz +++ b/tests/files/good-1-block_header-3.xz diff --git a/tests/files/good-1-check-crc32.xz b/tests/files/good-1-check-crc32.xz Binary files differindex 949a215d..6c89593d 100644 --- a/tests/files/good-1-check-crc32.xz +++ b/tests/files/good-1-check-crc32.xz diff --git a/tests/files/good-1-check-crc64.xz b/tests/files/good-1-check-crc64.xz Binary files differindex 6102c945..5a9915d2 100644 --- a/tests/files/good-1-check-crc64.xz +++ b/tests/files/good-1-check-crc64.xz diff --git a/tests/files/good-1-check-none.xz b/tests/files/good-1-check-none.xz Binary files differindex aab057d7..1e85faf3 100644 --- a/tests/files/good-1-check-none.xz +++ b/tests/files/good-1-check-none.xz diff --git a/tests/files/good-1-check-sha256.xz b/tests/files/good-1-check-sha256.xz Binary files differindex 141a4818..fdc556b6 100644 --- a/tests/files/good-1-check-sha256.xz +++ b/tests/files/good-1-check-sha256.xz diff --git a/tests/files/good-1-delta-lzma2.tiff.xz b/tests/files/good-1-delta-lzma2.tiff.xz Binary files differindex 744fb8d1..1f033bc5 100644 --- a/tests/files/good-1-delta-lzma2.tiff.xz +++ b/tests/files/good-1-delta-lzma2.tiff.xz diff --git a/tests/files/good-1-lzma2-1.xz b/tests/files/good-1-lzma2-1.xz Binary files differindex 96aff26e..d8d6489c 100644 --- a/tests/files/good-1-lzma2-1.xz +++ b/tests/files/good-1-lzma2-1.xz diff --git a/tests/files/good-1-lzma2-2.xz b/tests/files/good-1-lzma2-2.xz Binary files differindex 19631d48..7e8cdf1b 100644 --- a/tests/files/good-1-lzma2-2.xz +++ b/tests/files/good-1-lzma2-2.xz diff --git a/tests/files/good-1-lzma2-3.xz b/tests/files/good-1-lzma2-3.xz Binary files differindex 11c84ee6..c4c72be6 100644 --- a/tests/files/good-1-lzma2-3.xz +++ b/tests/files/good-1-lzma2-3.xz diff --git a/tests/files/good-1-sparc-lzma2.xz b/tests/files/good-1-sparc-lzma2.xz Binary files differindex 9111e39b..5c1c8600 100644 --- a/tests/files/good-1-sparc-lzma2.xz +++ b/tests/files/good-1-sparc-lzma2.xz diff --git a/tests/files/good-1-x86-lzma2.xz b/tests/files/good-1-x86-lzma2.xz Binary files differindex 4fbd0ee4..2c4a471a 100644 --- a/tests/files/good-1-x86-lzma2.xz +++ b/tests/files/good-1-x86-lzma2.xz diff --git a/tests/files/good-2-lzma2.xz b/tests/files/good-2-lzma2.xz Binary files differindex dd34b66a..bed5085c 100644 --- a/tests/files/good-2-lzma2.xz +++ b/tests/files/good-2-lzma2.xz diff --git a/tests/files/unsupported-block_header.xz b/tests/files/unsupported-block_header.xz Binary files differindex ee697e4d..38304429 100644 --- a/tests/files/unsupported-block_header.xz +++ b/tests/files/unsupported-block_header.xz diff --git a/tests/files/unsupported-check.xz b/tests/files/unsupported-check.xz Binary files differindex e2fe486b..c28355e7 100644 --- a/tests/files/unsupported-check.xz +++ b/tests/files/unsupported-check.xz diff --git a/tests/files/unsupported-filter_flags-1.xz b/tests/files/unsupported-filter_flags-1.xz Binary files differindex b4acab24..48b93731 100644 --- a/tests/files/unsupported-filter_flags-1.xz +++ b/tests/files/unsupported-filter_flags-1.xz diff --git a/tests/files/unsupported-filter_flags-2.xz b/tests/files/unsupported-filter_flags-2.xz Binary files differindex fa907dc2..c283359d 100644 --- a/tests/files/unsupported-filter_flags-2.xz +++ b/tests/files/unsupported-filter_flags-2.xz diff --git a/tests/files/unsupported-filter_flags-3.xz b/tests/files/unsupported-filter_flags-3.xz Binary files differindex 939ab5fe..26084984 100644 --- a/tests/files/unsupported-filter_flags-3.xz +++ b/tests/files/unsupported-filter_flags-3.xz diff --git a/tests/test_block_header.c b/tests/test_block_header.c index 4d398095..5c0f8b9a 100644 --- a/tests/test_block_header.c +++ b/tests/test_block_header.c @@ -89,7 +89,7 @@ code(void) { expect(lzma_block_header_encode(&known_options, buf) == LZMA_OK); - lzma_filter filters[LZMA_BLOCK_FILTERS_MAX + 1]; + lzma_filter filters[LZMA_FILTERS_MAX + 1]; memcrap(filters, sizeof(filters)); memcrap(&decoded_options, sizeof(decoded_options)); @@ -108,7 +108,7 @@ code(void) != LZMA_VLI_UNKNOWN; ++i) expect(known_options.filters[i].id == filters[i].id); - for (size_t i = 0; i < LZMA_BLOCK_FILTERS_MAX; ++i) + for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) free(decoded_options.filters[i].options); } @@ -137,12 +137,18 @@ test1(void) known_options.check = 999; // Some invalid value, which gets ignored. expect(lzma_block_header_size(&known_options) == LZMA_OK); - known_options.compressed_size = 5; // Not a multiple of four. - expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + known_options.compressed_size = 5; + expect(lzma_block_header_size(&known_options) == LZMA_OK); known_options.compressed_size = 0; // Cannot be zero. expect(lzma_block_header_size(&known_options) == LZMA_PROG_ERROR); + // LZMA_VLI_MAX is too big to keep the total size of the Block + // a valid VLI, but lzma_block_header_size() is not meant + // to validate it. (lzma_block_header_encode() must validate it.) + known_options.compressed_size = LZMA_VLI_MAX; + expect(lzma_block_header_size(&known_options) == LZMA_OK); + known_options.compressed_size = LZMA_VLI_UNKNOWN; known_options.uncompressed_size = 0; expect(lzma_block_header_size(&known_options) == LZMA_OK); @@ -192,7 +198,7 @@ test3(void) known_options.header_size += 4; expect(lzma_block_header_encode(&known_options, buf) == LZMA_OK); - lzma_filter filters[LZMA_BLOCK_FILTERS_MAX + 1]; + lzma_filter filters[LZMA_FILTERS_MAX + 1]; decoded_options.header_size = known_options.header_size; decoded_options.check = known_options.check; decoded_options.filters = filters; diff --git a/tests/test_index.c b/tests/test_index.c index 8a88dd31..d9d4e047 100644 --- a/tests/test_index.c +++ b/tests/test_index.c @@ -34,9 +34,9 @@ create_small(void) { lzma_index *i = lzma_index_init(NULL, NULL); expect(i != NULL); - expect(lzma_index_append(i, NULL, 400, 555) == LZMA_OK); - expect(lzma_index_append(i, NULL, 600, 777) == LZMA_OK); - expect(lzma_index_append(i, NULL, 800, 999) == LZMA_OK); + expect(lzma_index_append(i, NULL, 101, 555) == LZMA_OK); + expect(lzma_index_append(i, NULL, 602, 777) == LZMA_OK); + expect(lzma_index_append(i, NULL, 804, 999) == LZMA_OK); return i; } @@ -55,9 +55,9 @@ create_big(void) uint32_t n = 11; for (size_t j = 0; j < count; ++j) { n = 7019 * n + 7607; - const uint32_t t = (n * 3011) & ~UINT32_C(3); + const uint32_t t = n * 3011; expect(lzma_index_append(i, NULL, t, n) == LZMA_OK); - total_size += t; + total_size += (t + 3) & ~LZMA_VLI_C(3); uncompressed_size += n; } @@ -184,7 +184,7 @@ test_code(lzma_index *i) lzma_index_rewind(i); lzma_index_record r; while (!lzma_index_read(i, &r)) - expect(lzma_index_hash_append(h, r.total_size, + expect(lzma_index_hash_append(h, r.unpadded_size, r.uncompressed_size) == LZMA_OK); size_t pos = 0; while (pos < index_size - 1) @@ -302,7 +302,7 @@ test_locate(void) expect(!lzma_index_locate(i, &r, 0)); expect(r.total_size == 32); expect(r.uncompressed_size == 5); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 16); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 16); expect(r.uncompressed_offset == 0); // Still cannot find anything past the end. @@ -314,31 +314,31 @@ test_locate(void) expect(!lzma_index_locate(i, &r, 0)); expect(r.total_size == 32); expect(r.uncompressed_size == 5); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 16); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 16); expect(r.uncompressed_offset == 0); expect(!lzma_index_read(i, &r)); expect(r.total_size == 40); expect(r.uncompressed_size == 11); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 16 + 32); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 16 + 32); expect(r.uncompressed_offset == 5); expect(!lzma_index_locate(i, &r, 2)); expect(r.total_size == 32); expect(r.uncompressed_size == 5); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 16); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 16); expect(r.uncompressed_offset == 0); expect(!lzma_index_locate(i, &r, 5)); expect(r.total_size == 40); expect(r.uncompressed_size == 11); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 16 + 32); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 16 + 32); expect(r.uncompressed_offset == 5); expect(!lzma_index_locate(i, &r, 5 + 11 - 1)); expect(r.total_size == 40); expect(r.uncompressed_size == 11); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 16 + 32); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 16 + 32); expect(r.uncompressed_offset == 5); expect(lzma_index_locate(i, &r, 5 + 11)); @@ -357,27 +357,27 @@ test_locate(void) expect(!lzma_index_locate(i, &r, 0)); expect(r.total_size == 4 + 8); expect(r.uncompressed_size == 4); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE); expect(r.uncompressed_offset == 0); expect(!lzma_index_locate(i, &r, 3)); expect(r.total_size == 4 + 8); expect(r.uncompressed_size == 4); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE); expect(r.uncompressed_offset == 0); // Second Record expect(!lzma_index_locate(i, &r, 4)); expect(r.total_size == 2 * 4 + 8); expect(r.uncompressed_size == 2 * 4); - expect(r.stream_offset = LZMA_STREAM_HEADER_SIZE + 4 + 8); + expect(r.stream_offset == LZMA_STREAM_HEADER_SIZE + 4 + 8); expect(r.uncompressed_offset == 4); // Last Record expect(!lzma_index_locate(i, &r, lzma_index_uncompressed_size(i) - 1)); expect(r.total_size == 4 * 5555 + 8); expect(r.uncompressed_size == 4 * 5555); - expect(r.stream_offset = lzma_index_total_size(i) + expect(r.stream_offset == lzma_index_total_size(i) + LZMA_STREAM_HEADER_SIZE - 4 * 5555 - 8); expect(r.uncompressed_offset == lzma_index_uncompressed_size(i) - 4 * 5555); @@ -452,15 +452,7 @@ test_corrupt(void) lzma_stream strm = LZMA_STREAM_INIT; lzma_index *i = create_empty(); - expect(lzma_index_append(i, NULL, 7, 1) == LZMA_OK); - expect(lzma_index_encoder(&strm, i) == LZMA_OK); - succeed(coder_loop(&strm, NULL, 0, buf, 2, LZMA_PROG_ERROR, LZMA_RUN)); - lzma_index_end(i, NULL); - - i = create_empty(); - expect(lzma_index_append(i, NULL, 0, 1) == LZMA_OK); - expect(lzma_index_encoder(&strm, i) == LZMA_OK); - succeed(coder_loop(&strm, NULL, 0, buf, 2, LZMA_PROG_ERROR, LZMA_RUN)); + expect(lzma_index_append(i, NULL, 0, 1) == LZMA_PROG_ERROR); lzma_index_end(i, NULL); // Create a valid Index and corrupt it in different ways. |