コード例 #1
0
ファイル: test_index.c プロジェクト: Bludge0n/AREsoft
int
main(void)
{
    test_equal();

    test_overflow();

    lzma_index *i = create_empty();
    test_many(i);
    lzma_index_end(i, NULL);

    i = create_small();
    test_many(i);
    lzma_index_end(i, NULL);

    i = create_big();
    test_many(i);
    lzma_index_end(i, NULL);

    test_cat();

    test_locate();

    test_corrupt();

    return 0;
}
コード例 #2
0
int
main(void)
{
	test_equal();

	test_overflow();

	lzma_index *i = create_empty();
	test_many(i);
	lzma_index_end(i, NULL);

	i = create_small();
	test_many(i);
	lzma_index_end(i, NULL);

	i = create_big();
	test_many(i);
	lzma_index_end(i, NULL);

	test_cat();

	test_locate();

	test_corrupt();

	// Test for the bug fix 21515d79d778b8730a434f151b07202d52a04611:
	// liblzma: Fix lzma_index_dup() for empty Streams.
	i = create_empty();
	expect(lzma_index_stream_padding(i, 4) == LZMA_OK);
	test_copy(i);
	lzma_index_end(i, NULL);

	// Test for the bug fix 3bf857edfef51374f6f3fffae3d817f57d3264a0:
	// liblzma: Fix a memory leak in error path of lzma_index_dup().
	// Use Valgrind to see that there are no leaks.
	i = create_small();
	expect(lzma_index_dup(i, &my_allocator) == NULL);
	lzma_index_end(i, NULL);

	return 0;
}
コード例 #3
0
ファイル: test_index.c プロジェクト: Bludge0n/AREsoft
static void
test_equal(void)
{
    lzma_index *a = create_empty();
    lzma_index *b = create_small();
    lzma_index *c = create_big();
    expect(a && b && c);

    expect(is_equal(a, a));
    expect(is_equal(b, b));
    expect(is_equal(c, c));

    expect(!is_equal(a, b));
    expect(!is_equal(a, c));
    expect(!is_equal(b, c));

    lzma_index_end(a, NULL);
    lzma_index_end(b, NULL);
    lzma_index_end(c, NULL);
}
コード例 #4
0
ファイル: test_index.c プロジェクト: Bludge0n/AREsoft
static void
test_corrupt(void)
{
    const size_t alloc_size = 128 * 1024;
    uint8_t *buf = malloc(alloc_size);
    expect(buf != NULL);
    lzma_stream strm = LZMA_STREAM_INIT;

    lzma_index *i = create_empty();
    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.
    i = create_small();
    expect(lzma_index_encoder(&strm, i) == LZMA_OK);
    succeed(coder_loop(&strm, NULL, 0, buf, 20,
                       LZMA_STREAM_END, LZMA_RUN));
    lzma_index_end(i, NULL);

    // Wrong Index Indicator
    buf[0] ^= 1;
    expect(lzma_index_decoder(&strm, &i, MEMLIMIT) == LZMA_OK);
    succeed(decoder_loop_ret(&strm, buf, 1, LZMA_DATA_ERROR));
    buf[0] ^= 1;

    // Wrong Number of Records and thus CRC32 fails.
    --buf[1];
    expect(lzma_index_decoder(&strm, &i, MEMLIMIT) == LZMA_OK);
    succeed(decoder_loop_ret(&strm, buf, 10, LZMA_DATA_ERROR));
    ++buf[1];

    // Padding not NULs
    buf[15] ^= 1;
    expect(lzma_index_decoder(&strm, &i, MEMLIMIT) == LZMA_OK);
    succeed(decoder_loop_ret(&strm, buf, 16, LZMA_DATA_ERROR));

    lzma_end(&strm);
    free(buf);
}
コード例 #5
0
ファイル: test_index.c プロジェクト: Bludge0n/AREsoft
static void
test_cat(void)
{
    lzma_index *a, *b, *c;
    lzma_index_iter r;

    // Empty Indexes
    a = create_empty();
    b = create_empty();
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_block_count(a) == 0);
    expect(lzma_index_stream_size(a) == 2 * LZMA_STREAM_HEADER_SIZE + 8);
    expect(lzma_index_file_size(a)
           == 2 * (2 * LZMA_STREAM_HEADER_SIZE + 8));
    lzma_index_iter_init(&r, a);
    expect(lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK));

    b = create_empty();
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_block_count(a) == 0);
    expect(lzma_index_stream_size(a) == 2 * LZMA_STREAM_HEADER_SIZE + 8);
    expect(lzma_index_file_size(a)
           == 3 * (2 * LZMA_STREAM_HEADER_SIZE + 8));

    b = create_empty();
    c = create_empty();
    expect(lzma_index_stream_padding(b, 4) == LZMA_OK);
    expect(lzma_index_cat(b, c, NULL) == LZMA_OK);
    expect(lzma_index_block_count(b) == 0);
    expect(lzma_index_stream_size(b) == 2 * LZMA_STREAM_HEADER_SIZE + 8);
    expect(lzma_index_file_size(b)
           == 2 * (2 * LZMA_STREAM_HEADER_SIZE + 8) + 4);

    expect(lzma_index_stream_padding(a, 8) == LZMA_OK);
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_block_count(a) == 0);
    expect(lzma_index_stream_size(a) == 2 * LZMA_STREAM_HEADER_SIZE + 8);
    expect(lzma_index_file_size(a)
           == 5 * (2 * LZMA_STREAM_HEADER_SIZE + 8) + 4 + 8);

    expect(lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK));
    lzma_index_iter_rewind(&r);
    expect(lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK));
    lzma_index_end(a, NULL);

    // Small Indexes
    a = create_small();
    lzma_vli stream_size = lzma_index_stream_size(a);
    lzma_index_iter_init(&r, a);
    for (int i = SMALL_COUNT; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    b = create_small();
    expect(lzma_index_stream_padding(a, 4) == LZMA_OK);
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_file_size(a) == stream_size * 2 + 4);
    expect(lzma_index_stream_size(a) > stream_size);
    expect(lzma_index_stream_size(a) < stream_size * 2);
    for (int i = SMALL_COUNT; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    lzma_index_iter_rewind(&r);
    for (int i = SMALL_COUNT * 2; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    b = create_small();
    c = create_small();
    expect(lzma_index_stream_padding(b, 8) == LZMA_OK);
    expect(lzma_index_cat(b, c, NULL) == LZMA_OK);
    expect(lzma_index_stream_padding(a, 12) == LZMA_OK);
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_file_size(a) == stream_size * 4 + 4 + 8 + 12);

    expect(lzma_index_block_count(a) == SMALL_COUNT * 4);
    for (int i = SMALL_COUNT * 2; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    lzma_index_iter_rewind(&r);
    for (int i = SMALL_COUNT * 4; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    lzma_index_end(a, NULL);

    // Mix of empty and small
    a = create_empty();
    b = create_small();
    expect(lzma_index_stream_padding(a, 4) == LZMA_OK);
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    lzma_index_iter_init(&r, a);
    for (int i = SMALL_COUNT; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    lzma_index_end(a, NULL);

    // Big Indexes
    a = create_big();
    stream_size = lzma_index_stream_size(a);
    b = create_big();
    expect(lzma_index_stream_padding(a, 4) == LZMA_OK);
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_file_size(a) == stream_size * 2 + 4);
    expect(lzma_index_stream_size(a) > stream_size);
    expect(lzma_index_stream_size(a) < stream_size * 2);

    b = create_big();
    c = create_big();
    expect(lzma_index_stream_padding(b, 8) == LZMA_OK);
    expect(lzma_index_cat(b, c, NULL) == LZMA_OK);
    expect(lzma_index_stream_padding(a, 12) == LZMA_OK);
    expect(lzma_index_cat(a, b, NULL) == LZMA_OK);
    expect(lzma_index_file_size(a) == stream_size * 4 + 4 + 8 + 12);

    lzma_index_iter_init(&r, a);
    for (int i = BIG_COUNT * 4; i >= 0; --i)
        expect(!lzma_index_iter_next(&r, LZMA_INDEX_ITER_BLOCK)
               ^ (i == 0));

    lzma_index_end(a, NULL);
}