mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
Merge branch 'm1c-decoder-extensions' into claude/project-thread-0izcgq
Combines the encoder (quality 0 and 1) with the decoder's large-window mode and custom dictionaries. The test and mimic files take both sides' new sections; the fuzzer gains the std/softfloat module that the encoder now pulls into std/brotli. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011NoosQNe7DKWnqDCBeqw1p
This commit is contained in:
42 files changed
+4220
-461
No files matched your search
@@ -539,6 +539,7 @@ brotli_c_error_code(const char* status) {
|
||||
{wuffs_brotli__error__bad_final_padding, -15},
|
||||
{wuffs_brotli__error__bad_distance, -16},
|
||||
{wuffs_brotli__error__bad_block_switch, -17},
|
||||
{wuffs_brotli__error__bad_compound_dictionary, -18},
|
||||
{wuffs_brotli__error__truncated_input, 2},
|
||||
};
|
||||
if (!status) {
|
||||
@@ -1664,6 +1665,855 @@ bench_mimic_brotli_encode_alice29_q1() {
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Large Window and Dictionary Tests
|
||||
|
||||
// See test/data/brotli/README.md for where the large-window (lw), raw
|
||||
// dictionary (raw) and serialized shared dictionary (sd) test files came from.
|
||||
|
||||
typedef struct {
|
||||
uint32_t type; // WUFFS_BROTLI__DICTIONARY_TYPE_ETC.
|
||||
const char* filename;
|
||||
// lo and hi select the [lo .. hi) bytes of the file. A zero hi means the
|
||||
// whole file.
|
||||
size_t lo;
|
||||
size_t hi;
|
||||
} brotli_dict_spec;
|
||||
|
||||
#define BROTLI_DICT_SPECS_MAX 4
|
||||
|
||||
// g_brotli_dict_sets lists the sets of dictionaries (attached in order) that
|
||||
// the test files use. A NULL filename terminates each set.
|
||||
struct {
|
||||
brotli_dict_spec specs[BROTLI_DICT_SPECS_MAX];
|
||||
} g_brotli_dict_sets[] = {
|
||||
#define BROTLI_DICT_SET_NONE 0
|
||||
{{{0, NULL, 0, 0}}},
|
||||
#define BROTLI_DICT_SET_RAW_ROMEO 1
|
||||
{{{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/romeo.txt", 0, 0}}},
|
||||
#define BROTLI_DICT_SET_RAW_ALICE_CHUNKS 2
|
||||
{{
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/brotli/alice29.txt", 0,
|
||||
20000},
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/brotli/alice29.txt",
|
||||
20000, 20001},
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/brotli/alice29.txt",
|
||||
20001, 20001},
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/brotli/alice29.txt",
|
||||
20001, 60000},
|
||||
}},
|
||||
#define BROTLI_DICT_SET_RAW_ROMEO_CHUNKS 3
|
||||
{{
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/romeo.txt", 0, 300},
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/romeo.txt", 300, 500},
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/romeo.txt", 500, 942},
|
||||
}},
|
||||
#define BROTLI_DICT_SET_SD_FULL 4
|
||||
{{{WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED,
|
||||
"test/data/brotli/shared-dictionary.full.bin", 0, 0}}},
|
||||
#define BROTLI_DICT_SET_SD_WORDS 5
|
||||
{{{WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED,
|
||||
"test/data/brotli/shared-dictionary.words.bin", 0, 0}}},
|
||||
#define BROTLI_DICT_SET_SD_PREFIX_AND_RAW 6
|
||||
{{
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED,
|
||||
"test/data/brotli/shared-dictionary.prefix.bin", 0, 0},
|
||||
{WUFFS_BROTLI__DICTIONARY_TYPE_RAW, "test/data/romeo.txt", 0, 300},
|
||||
}},
|
||||
#define BROTLI_DICT_SET_SD_UTF8 7
|
||||
{{{WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED,
|
||||
"test/data/brotli/shared-dictionary.utf8.bin", 0, 0}}},
|
||||
};
|
||||
|
||||
// g_brotli_ext_vectors lists (compressed, decompressed) pairs of test files
|
||||
// that need the large-window quirk or attached dictionaries.
|
||||
struct {
|
||||
const char* src_filename;
|
||||
const char* want_filename;
|
||||
bool large_window;
|
||||
size_t dict_set;
|
||||
} g_brotli_ext_vectors[] = {
|
||||
{"test/data/brotli/alice29.txt.q11lw26.br", "test/data/brotli/alice29.txt",
|
||||
true, BROTLI_DICT_SET_NONE},
|
||||
{"test/data/brotli/alice29.txt.q5lw10.br", "test/data/brotli/alice29.txt",
|
||||
true, BROTLI_DICT_SET_NONE},
|
||||
{"test/data/brotli/romeo.txt.q11lw30.br", "test/data/romeo.txt", true,
|
||||
BROTLI_DICT_SET_NONE},
|
||||
{"test/data/brotli/romeo.txt.q9lw28.br", "test/data/romeo.txt", true,
|
||||
BROTLI_DICT_SET_NONE},
|
||||
{"test/data/brotli/romeo.txt.q11w22.raw-romeo.br", "test/data/romeo.txt",
|
||||
false, BROTLI_DICT_SET_RAW_ROMEO},
|
||||
{"test/data/brotli/romeo.txt.q11lw30.raw-romeo.br", "test/data/romeo.txt",
|
||||
true, BROTLI_DICT_SET_RAW_ROMEO},
|
||||
{"test/data/brotli/alice29.txt.q5w18.raw-chunks.br",
|
||||
"test/data/brotli/alice29.txt", false, BROTLI_DICT_SET_RAW_ALICE_CHUNKS},
|
||||
{"test/data/brotli/alice29.txt.q11w18.raw-chunks.br",
|
||||
"test/data/brotli/alice29.txt", false, BROTLI_DICT_SET_RAW_ALICE_CHUNKS},
|
||||
{"test/data/brotli/romeo.txt.q11w16.raw-chunks.br", "test/data/romeo.txt",
|
||||
false, BROTLI_DICT_SET_RAW_ROMEO_CHUNKS},
|
||||
{"test/data/brotli/shared-dictionary.text.q5w18.sd-full.br",
|
||||
"test/data/brotli/shared-dictionary.text", false, BROTLI_DICT_SET_SD_FULL},
|
||||
{"test/data/brotli/shared-dictionary.text.q11w18.sd-full.br",
|
||||
"test/data/brotli/shared-dictionary.text", false, BROTLI_DICT_SET_SD_FULL},
|
||||
{"test/data/brotli/shared-dictionary.text.q11lw24.sd-full.br",
|
||||
"test/data/brotli/shared-dictionary.text", true, BROTLI_DICT_SET_SD_FULL},
|
||||
{"test/data/brotli/alice29.txt.q11w22.sd-words.br",
|
||||
"test/data/brotli/alice29.txt", false, BROTLI_DICT_SET_SD_WORDS},
|
||||
{"test/data/brotli/asyoulik.txt.q11w18.sd-prefix-raw.br",
|
||||
"test/data/brotli/asyoulik.txt", false, BROTLI_DICT_SET_SD_PREFIX_AND_RAW},
|
||||
{"test/data/brotli/romeo-mutated.sd-utf8.br",
|
||||
"test/data/brotli/romeo-mutated.sd-utf8.txt", false,
|
||||
BROTLI_DICT_SET_SD_UTF8},
|
||||
};
|
||||
|
||||
// g_brotli_ext_malformed is like g_brotli_malformed but for inputs that need
|
||||
// the large-window quirk or attached dictionaries. The invalid.lw-*,
|
||||
// invalid.raw-* and invalid.sd-* files were found by mutating the
|
||||
// g_brotli_ext_vectors files (see test/data/brotli/README.md).
|
||||
struct {
|
||||
const char* src_filename;
|
||||
const char* data;
|
||||
size_t len;
|
||||
bool large_window;
|
||||
size_t dict_set;
|
||||
const char* want_status;
|
||||
} g_brotli_ext_malformed[] = {
|
||||
// BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: the large-window escape
|
||||
// followed by a non-zero reserved bit.
|
||||
{NULL, "\x91", 1, true, BROTLI_DICT_SET_NONE,
|
||||
wuffs_brotli__error__bad_window_bits},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: large-window WBITS of 9 (too
|
||||
// small) and 62 (too large).
|
||||
{NULL, "\x11\x09", 2, true, BROTLI_DICT_SET_NONE,
|
||||
wuffs_brotli__error__bad_window_bits},
|
||||
{NULL, "\x11\x3E", 2, true, BROTLI_DICT_SET_NONE,
|
||||
wuffs_brotli__error__bad_window_bits},
|
||||
// BROTLI_DECODER_NEEDS_MORE_INPUT: a truncated large-window header.
|
||||
{NULL, "\x11", 1, true, BROTLI_DICT_SET_NONE,
|
||||
wuffs_brotli__error__truncated_input},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: a large-window stream without
|
||||
// the large-window quirk.
|
||||
{"test/data/brotli/romeo.txt.q11lw30.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_NONE, wuffs_brotli__error__unsupported_large_window},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_DISTANCE.
|
||||
{"test/data/brotli/invalid.lw-distance.br", NULL, 0, true,
|
||||
BROTLI_DICT_SET_NONE, wuffs_brotli__error__bad_distance},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_DICTIONARY.
|
||||
{"test/data/brotli/invalid.lw-dictionary.br", NULL, 0, true,
|
||||
BROTLI_DICT_SET_NONE, wuffs_brotli__error__bad_dictionary},
|
||||
// BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY.
|
||||
{"test/data/brotli/invalid.raw-compound-dictionary.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_RAW_ROMEO_CHUNKS,
|
||||
wuffs_brotli__error__bad_compound_dictionary},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_DICTIONARY.
|
||||
{"test/data/brotli/invalid.raw-dictionary.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_RAW_ROMEO_CHUNKS, wuffs_brotli__error__bad_dictionary},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_TRANSFORM.
|
||||
{"test/data/brotli/invalid.raw-transform.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_RAW_ROMEO_CHUNKS, wuffs_brotli__error__bad_transform},
|
||||
// BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY: a stream compressed without
|
||||
// a dictionary refers to the static dictionary, but with a compound
|
||||
// dictionary attached, the same distance refers to the compound
|
||||
// dictionary.
|
||||
{"test/data/brotli/romeo.txt.q11w22.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_SD_FULL, wuffs_brotli__error__bad_compound_dictionary},
|
||||
// BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY.
|
||||
{"test/data/brotli/invalid.sd-compound-dictionary.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_SD_FULL, wuffs_brotli__error__bad_compound_dictionary},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_DICTIONARY.
|
||||
{"test/data/brotli/invalid.sd-dictionary.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_SD_FULL, wuffs_brotli__error__bad_dictionary},
|
||||
// BROTLI_DECODER_ERROR_FORMAT_TRANSFORM.
|
||||
{"test/data/brotli/invalid.sd-transform.br", NULL, 0, false,
|
||||
BROTLI_DICT_SET_SD_FULL, wuffs_brotli__error__bad_transform},
|
||||
{"test/data/brotli/invalid.lw-sd-transform.br", NULL, 0, true,
|
||||
BROTLI_DICT_SET_SD_FULL, wuffs_brotli__error__bad_transform},
|
||||
};
|
||||
|
||||
// g_brotli_dict_arrays holds the dictionaries' bytes.
|
||||
uint8_t g_brotli_dict_arrays[BROTLI_DICT_SPECS_MAX][256 * 1024];
|
||||
|
||||
// load_brotli_dict_set loads the dict_set'th g_brotli_dict_sets entry.
|
||||
const char* //
|
||||
load_brotli_dict_set(size_t dict_set,
|
||||
size_t* num_dicts,
|
||||
uint32_t* dict_types,
|
||||
wuffs_base__slice_u8* dicts) {
|
||||
*num_dicts = 0;
|
||||
if (dict_set >= WUFFS_TESTLIB_ARRAY_SIZE(g_brotli_dict_sets)) {
|
||||
return "load_brotli_dict_set: dict_set out of range";
|
||||
}
|
||||
for (size_t i = 0; i < BROTLI_DICT_SPECS_MAX; i++) {
|
||||
const brotli_dict_spec* spec = &g_brotli_dict_sets[dict_set].specs[i];
|
||||
if (!spec->filename) {
|
||||
break;
|
||||
}
|
||||
wuffs_base__io_buffer buf = ((wuffs_base__io_buffer){
|
||||
.data = wuffs_base__make_slice_u8(g_brotli_dict_arrays[i],
|
||||
sizeof g_brotli_dict_arrays[i]),
|
||||
});
|
||||
CHECK_STRING(read_file(&buf, spec->filename));
|
||||
size_t hi = spec->hi ? spec->hi : buf.meta.wi;
|
||||
if ((spec->lo > hi) || (hi > buf.meta.wi)) {
|
||||
return "load_brotli_dict_set: bad lo/hi";
|
||||
}
|
||||
dict_types[i] = spec->type;
|
||||
dicts[i] = wuffs_base__make_slice_u8(buf.data.ptr + spec->lo,
|
||||
hi - spec->lo);
|
||||
*num_dicts = i + 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// get_brotli_big_workbuf sets *workbuf to a malloc'ed buffer that is large
|
||||
// enough for any large-window stream and 1 MiB of dictionaries. It is never
|
||||
// freed. Only the parts of it that the decoder uses are touched, so the
|
||||
// operating system should only need to commit as much memory as the stream's
|
||||
// window size.
|
||||
const char* //
|
||||
get_brotli_big_workbuf(wuffs_base__slice_u8* workbuf) {
|
||||
static uint8_t* ptr = NULL;
|
||||
const size_t n = WUFFS_BROTLI__DECODER_WORKBUF_LEN_LARGE_WINDOW + (1 << 20);
|
||||
if (!ptr) {
|
||||
ptr = (uint8_t*)malloc(n);
|
||||
if (!ptr) {
|
||||
return "get_brotli_big_workbuf: out of memory";
|
||||
}
|
||||
}
|
||||
*workbuf = wuffs_base__make_slice_u8(ptr, n);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// wuffs_brotli_decode_with_options is like wuffs_brotli_decode but it can
|
||||
// also set the large-window quirk and attach dictionaries.
|
||||
const char* //
|
||||
wuffs_brotli_decode_with_options(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
bool large_window,
|
||||
size_t dict_set) {
|
||||
size_t num_dicts = 0;
|
||||
uint32_t dict_types[BROTLI_DICT_SPECS_MAX] = {0};
|
||||
wuffs_base__slice_u8 dicts[BROTLI_DICT_SPECS_MAX] = {0};
|
||||
CHECK_STRING(load_brotli_dict_set(dict_set, &num_dicts, dict_types, dicts));
|
||||
|
||||
wuffs_brotli__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_brotli__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
// The large-window workbuf_len (more than 1 GiB) is larger than
|
||||
// g_work_slice_u8.
|
||||
wuffs_base__slice_u8 workbuf = g_work_slice_u8;
|
||||
if (large_window) {
|
||||
CHECK_STATUS("set_quirk",
|
||||
wuffs_brotli__decoder__set_quirk(
|
||||
&dec, WUFFS_BROTLI__QUIRK_LARGE_WINDOW, 1));
|
||||
CHECK_STRING(get_brotli_big_workbuf(&workbuf));
|
||||
}
|
||||
for (size_t i = 0; i < num_dicts; i++) {
|
||||
CHECK_STATUS("add_dictionary",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, dict_types[i], dicts[i], workbuf));
|
||||
}
|
||||
wuffs_base__range_ii_u64 workbuf_len =
|
||||
wuffs_brotli__decoder__workbuf_len(&dec);
|
||||
if (workbuf_len.max_incl > workbuf.len) {
|
||||
return "workbuf_len is too large";
|
||||
}
|
||||
workbuf.len = workbuf_len.max_incl;
|
||||
|
||||
while (true) {
|
||||
wuffs_base__io_buffer limited_dst = make_limited_writer(*dst, wlimit);
|
||||
wuffs_base__io_buffer limited_src = make_limited_reader(*src, rlimit);
|
||||
|
||||
wuffs_base__status status = wuffs_brotli__decoder__transform_io(
|
||||
&dec, &limited_dst, &limited_src, workbuf);
|
||||
|
||||
dst->meta.wi += limited_dst.meta.wi;
|
||||
src->meta.ri += limited_src.meta.ri;
|
||||
|
||||
if (((wlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_write)) ||
|
||||
((rlimit < UINT64_MAX) &&
|
||||
(status.repr == wuffs_base__suspension__short_read))) {
|
||||
continue;
|
||||
}
|
||||
return status.repr;
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test_brotli_decode_ext_all(uint64_t wlimit, uint64_t rlimit) {
|
||||
size_t n = WUFFS_TESTLIB_ARRAY_SIZE(g_brotli_ext_vectors);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, g_brotli_ext_vectors[i].src_filename));
|
||||
CHECK_STRING(read_file(&want, g_brotli_ext_vectors[i].want_filename));
|
||||
const char* status = wuffs_brotli_decode_with_options(
|
||||
&have, &src, wlimit, rlimit, g_brotli_ext_vectors[i].large_window,
|
||||
g_brotli_ext_vectors[i].dict_set);
|
||||
if (status) {
|
||||
RETURN_FAIL("%s: %s", g_brotli_ext_vectors[i].src_filename, status);
|
||||
}
|
||||
status = check_io_buffers_equal("", &have, &want);
|
||||
if (status) {
|
||||
RETURN_FAIL("%s: %s", g_brotli_ext_vectors[i].src_filename, status);
|
||||
}
|
||||
if (src.meta.ri != src.meta.wi) {
|
||||
RETURN_FAIL("%s: ri: have %zu, want %zu",
|
||||
g_brotli_ext_vectors[i].src_filename, src.meta.ri,
|
||||
src.meta.wi);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_brotli_decode_ext_all() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_brotli_decode_ext_all(UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_brotli_decode_ext_all_with_io_limits() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_brotli_decode_ext_all(1, 1);
|
||||
}
|
||||
|
||||
// make_brotli_far_data writes the decompressed form of
|
||||
// test/data/brotli/far17m.q9lw25.br: 64 KiB of xorshift32 output, 17 MiB of
|
||||
// zeroes and the same 64 KiB again. Its second 64 KiB copy is more than
|
||||
// (1 << 24) bytes after the first.
|
||||
const char* //
|
||||
make_brotli_far_data(wuffs_base__io_buffer* dst) {
|
||||
const size_t a = 65536;
|
||||
const size_t z = 17 << 20;
|
||||
if ((dst->data.len - dst->meta.wi) < (a + z + a)) {
|
||||
return "make_brotli_far_data: dst is too short";
|
||||
}
|
||||
uint8_t* p = dst->data.ptr + dst->meta.wi;
|
||||
uint32_t x = 0x12345678;
|
||||
for (size_t i = 0; i < a; i++) {
|
||||
x ^= x << 13;
|
||||
x ^= x >> 17;
|
||||
x ^= x << 5;
|
||||
p[i] = (uint8_t)(x >> 24);
|
||||
}
|
||||
memset(p + a, 0, z);
|
||||
memcpy(p + a + z, p, a);
|
||||
dst->meta.wi += a + z + a;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test_brotli_decode_large_window_far(
|
||||
const char* (*codec_func)(wuffs_base__io_buffer*,
|
||||
wuffs_base__io_buffer*,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
bool,
|
||||
size_t),
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/brotli/far17m.q9lw25.br"));
|
||||
CHECK_STRING(make_brotli_far_data(&want));
|
||||
CHECK_STRING(
|
||||
(*codec_func)(&have, &src, wlimit, rlimit, true, BROTLI_DICT_SET_NONE));
|
||||
return check_io_buffers_equal("", &have, &want);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_brotli_decode_large_window_far() {
|
||||
CHECK_FOCUS(__func__);
|
||||
CHECK_STRING(do_test_brotli_decode_large_window_far(
|
||||
wuffs_brotli_decode_with_options, UINT64_MAX, UINT64_MAX));
|
||||
return do_test_brotli_decode_large_window_far(
|
||||
wuffs_brotli_decode_with_options, 4099, 113);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_brotli_decode_large_window_quirk() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
// With the quirk set, standard (not large-window) streams still decode.
|
||||
size_t n = WUFFS_TESTLIB_ARRAY_SIZE(g_brotli_vectors);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, g_brotli_vectors[i].src_filename));
|
||||
CHECK_STRING(read_file(&want, g_brotli_vectors[i].want_filename));
|
||||
const char* status = wuffs_brotli_decode_with_options(
|
||||
&have, &src, UINT64_MAX, UINT64_MAX, true, BROTLI_DICT_SET_NONE);
|
||||
if (status) {
|
||||
RETURN_FAIL("%s: %s", g_brotli_vectors[i].src_filename, status);
|
||||
}
|
||||
CHECK_STRING(check_io_buffers_equal("", &have, &want));
|
||||
}
|
||||
|
||||
// The quirk's value and the workbuf_len.
|
||||
wuffs_brotli__decoder dec;
|
||||
CHECK_STATUS("initialize", wuffs_brotli__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
if (wuffs_brotli__decoder__get_quirk(&dec,
|
||||
WUFFS_BROTLI__QUIRK_LARGE_WINDOW) != 0) {
|
||||
RETURN_FAIL("get_quirk #0: have non-zero, want zero");
|
||||
}
|
||||
wuffs_base__range_ii_u64 r = wuffs_brotli__decoder__workbuf_len(&dec);
|
||||
if ((r.min_incl != WUFFS_BROTLI__DECODER_WORKBUF_LEN_STANDARD) ||
|
||||
(r.max_incl != WUFFS_BROTLI__DECODER_WORKBUF_LEN_STANDARD) ||
|
||||
(r.max_incl != ((1 << 24) + 542))) {
|
||||
RETURN_FAIL("workbuf_len #0: have %" PRIu64, r.max_incl);
|
||||
}
|
||||
CHECK_STATUS("set_quirk", wuffs_brotli__decoder__set_quirk(
|
||||
&dec, WUFFS_BROTLI__QUIRK_LARGE_WINDOW, 1));
|
||||
if (wuffs_brotli__decoder__get_quirk(&dec,
|
||||
WUFFS_BROTLI__QUIRK_LARGE_WINDOW) != 1) {
|
||||
RETURN_FAIL("get_quirk #1: have zero, want non-zero");
|
||||
}
|
||||
r = wuffs_brotli__decoder__workbuf_len(&dec);
|
||||
if ((r.min_incl != r.max_incl) ||
|
||||
(r.max_incl != WUFFS_BROTLI__DECODER_WORKBUF_LEN_LARGE_WINDOW) ||
|
||||
(r.max_incl != ((1 << 30) + 542))) {
|
||||
RETURN_FAIL("workbuf_len #1: have %" PRIu64, r.max_incl);
|
||||
}
|
||||
|
||||
// Quirks cannot be set after decoding has started.
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/brotli/alice29.txt.q5lw10.br"));
|
||||
src.meta.wi = 3;
|
||||
src.meta.closed = false;
|
||||
wuffs_base__slice_u8 workbuf = g_work_slice_u8;
|
||||
wuffs_base__status status =
|
||||
wuffs_brotli__decoder__transform_io(&dec, &have, &src, workbuf);
|
||||
if (status.repr != wuffs_base__suspension__short_read) {
|
||||
RETURN_FAIL("transform_io: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__suspension__short_read);
|
||||
}
|
||||
status = wuffs_brotli__decoder__set_quirk(
|
||||
&dec, WUFFS_BROTLI__QUIRK_LARGE_WINDOW, 0);
|
||||
if (status.repr != wuffs_base__error__bad_call_sequence) {
|
||||
RETURN_FAIL("set_quirk: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_brotli_decode_ext_malformed() {
|
||||
CHECK_FOCUS(__func__);
|
||||
size_t n = WUFFS_TESTLIB_ARRAY_SIZE(g_brotli_ext_malformed);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
if (g_brotli_ext_malformed[i].src_filename) {
|
||||
CHECK_STRING(read_file(&src, g_brotli_ext_malformed[i].src_filename));
|
||||
} else {
|
||||
memcpy(src.data.ptr, g_brotli_ext_malformed[i].data,
|
||||
g_brotli_ext_malformed[i].len);
|
||||
src.meta.wi = g_brotli_ext_malformed[i].len;
|
||||
src.meta.closed = true;
|
||||
}
|
||||
uint64_t limit = (j == 0) ? UINT64_MAX : 1;
|
||||
const char* have_status = wuffs_brotli_decode_with_options(
|
||||
&have, &src, limit, limit, g_brotli_ext_malformed[i].large_window,
|
||||
g_brotli_ext_malformed[i].dict_set);
|
||||
const char* want_status = g_brotli_ext_malformed[i].want_status;
|
||||
if (have_status != want_status) {
|
||||
RETURN_FAIL("i=%zu, j=%d: have \"%s\", want \"%s\"", i, j, have_status,
|
||||
want_status);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_brotli_add_dictionary() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_base__io_buffer full = ((wuffs_base__io_buffer){
|
||||
.data = wuffs_base__make_slice_u8(g_brotli_dict_arrays[0],
|
||||
sizeof g_brotli_dict_arrays[0]),
|
||||
});
|
||||
wuffs_base__io_buffer words = ((wuffs_base__io_buffer){
|
||||
.data = wuffs_base__make_slice_u8(g_brotli_dict_arrays[1],
|
||||
sizeof g_brotli_dict_arrays[1]),
|
||||
});
|
||||
wuffs_base__io_buffer prefix = ((wuffs_base__io_buffer){
|
||||
.data = wuffs_base__make_slice_u8(g_brotli_dict_arrays[2],
|
||||
sizeof g_brotli_dict_arrays[2]),
|
||||
});
|
||||
CHECK_STRING(
|
||||
read_file(&full, "test/data/brotli/shared-dictionary.full.bin"));
|
||||
CHECK_STRING(
|
||||
read_file(&words, "test/data/brotli/shared-dictionary.words.bin"));
|
||||
CHECK_STRING(
|
||||
read_file(&prefix, "test/data/brotli/shared-dictionary.prefix.bin"));
|
||||
wuffs_base__slice_u8 full_s =
|
||||
wuffs_base__make_slice_u8(full.data.ptr, full.meta.wi);
|
||||
wuffs_base__slice_u8 words_s =
|
||||
wuffs_base__make_slice_u8(words.data.ptr, words.meta.wi);
|
||||
wuffs_base__slice_u8 prefix_s =
|
||||
wuffs_base__make_slice_u8(prefix.data.ptr, prefix.meta.wi);
|
||||
wuffs_base__slice_u8 raw_s =
|
||||
wuffs_base__make_slice_u8(prefix.data.ptr, 100);
|
||||
wuffs_base__slice_u8 workbuf = g_work_slice_u8;
|
||||
wuffs_brotli__decoder dec;
|
||||
wuffs_base__status status;
|
||||
|
||||
// An unknown dictionary type.
|
||||
CHECK_STATUS("initialize", wuffs_brotli__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
status = wuffs_brotli__decoder__add_dictionary(&dec, 2, raw_s, workbuf);
|
||||
if (status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL("type 2: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__error__bad_argument);
|
||||
}
|
||||
|
||||
// At most 15 compound (raw or prefix) dictionaries. The workbuf_len grows
|
||||
// with each one.
|
||||
for (int i = 0; i < 15; i++) {
|
||||
CHECK_STATUS("add_dictionary #0",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_RAW, raw_s, workbuf));
|
||||
wuffs_base__range_ii_u64 r = wuffs_brotli__decoder__workbuf_len(&dec);
|
||||
uint64_t want = WUFFS_BROTLI__DECODER_WORKBUF_LEN_STANDARD +
|
||||
(100 * ((uint64_t)i + 1));
|
||||
if ((r.min_incl != want) || (r.max_incl != want)) {
|
||||
RETURN_FAIL("workbuf_len: have %" PRIu64 ", want %" PRIu64, r.max_incl,
|
||||
want);
|
||||
}
|
||||
}
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_RAW, raw_s, workbuf);
|
||||
if (status.repr != wuffs_brotli__error__too_many_compound_dictionaries) {
|
||||
RETURN_FAIL("16th raw: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_brotli__error__too_many_compound_dictionaries);
|
||||
}
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, prefix_s, workbuf);
|
||||
if (status.repr != wuffs_brotli__error__too_many_compound_dictionaries) {
|
||||
RETURN_FAIL("16th prefix: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_brotli__error__too_many_compound_dictionaries);
|
||||
}
|
||||
// A serialized dictionary without a prefix is still OK.
|
||||
CHECK_STATUS("add_dictionary #1",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, words_s,
|
||||
workbuf));
|
||||
|
||||
// Only one serialized dictionary can have custom word or transform lists,
|
||||
// but a serialized dictionary without them (only a prefix) is OK.
|
||||
CHECK_STATUS("initialize", wuffs_brotli__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
CHECK_STATUS("add_dictionary #2",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, full_s,
|
||||
workbuf));
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, words_s, workbuf);
|
||||
if (status.repr !=
|
||||
wuffs_brotli__error__unsupported_multiple_custom_static_dictionaries) {
|
||||
RETURN_FAIL(
|
||||
"words after full: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_brotli__error__unsupported_multiple_custom_static_dictionaries);
|
||||
}
|
||||
CHECK_STATUS("add_dictionary #3",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, prefix_s,
|
||||
workbuf));
|
||||
// Attaching a prefix-only serialized dictionary resets the static
|
||||
// dictionary to the built-in one, so custom lists can be attached again.
|
||||
CHECK_STATUS("add_dictionary #4",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, words_s,
|
||||
workbuf));
|
||||
|
||||
// Invalid serialized dictionaries: every proper prefix of a valid one, and
|
||||
// a bad magic number. A failed add_dictionary does not change the
|
||||
// workbuf_len.
|
||||
CHECK_STATUS("initialize", wuffs_brotli__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
for (size_t i = 0; i < full_s.len; i++) {
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED,
|
||||
wuffs_base__make_slice_u8(full_s.ptr, i), workbuf);
|
||||
if (status.repr != wuffs_brotli__error__bad_shared_dictionary) {
|
||||
RETURN_FAIL("prefix length %zu: have \"%s\", want \"%s\"", i,
|
||||
status.repr, wuffs_brotli__error__bad_shared_dictionary);
|
||||
}
|
||||
}
|
||||
full_s.ptr[0] ^= 1;
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_SERIALIZED, full_s, workbuf);
|
||||
full_s.ptr[0] ^= 1;
|
||||
if (status.repr != wuffs_brotli__error__bad_shared_dictionary) {
|
||||
RETURN_FAIL("bad magic: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_brotli__error__bad_shared_dictionary);
|
||||
}
|
||||
if (wuffs_brotli__decoder__workbuf_len(&dec).max_incl !=
|
||||
WUFFS_BROTLI__DECODER_WORKBUF_LEN_STANDARD) {
|
||||
RETURN_FAIL("workbuf_len changed");
|
||||
}
|
||||
|
||||
// A too-short workbuf.
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_RAW, raw_s,
|
||||
wuffs_base__make_slice_u8(workbuf.ptr, 99));
|
||||
if (status.repr != wuffs_base__error__bad_workbuf_length) {
|
||||
RETURN_FAIL("short workbuf: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__error__bad_workbuf_length);
|
||||
}
|
||||
CHECK_STATUS("add_dictionary #5",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_RAW, raw_s,
|
||||
wuffs_base__make_slice_u8(workbuf.ptr, 100)));
|
||||
|
||||
// A transform_io workbuf that is shorter than the dictionaries.
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, "test/data/brotli/romeo.txt.q11w22.br"));
|
||||
status = wuffs_brotli__decoder__transform_io(
|
||||
&dec, &have, &src, wuffs_base__make_slice_u8(workbuf.ptr, 99));
|
||||
if (status.repr != wuffs_base__error__bad_workbuf_length) {
|
||||
RETURN_FAIL("transform_io: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__error__bad_workbuf_length);
|
||||
}
|
||||
|
||||
// Dictionaries cannot be added after decoding has started.
|
||||
CHECK_STATUS("initialize", wuffs_brotli__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__DEFAULT_OPTIONS));
|
||||
src.meta.ri = 0;
|
||||
src.meta.wi = 0;
|
||||
src.meta.closed = false;
|
||||
// With no input, decoding has not started (the C code is still in its
|
||||
// BROTLI_STATE_UNINITED state).
|
||||
status = wuffs_brotli__decoder__transform_io(&dec, &have, &src, workbuf);
|
||||
if (status.repr != wuffs_base__suspension__short_read) {
|
||||
RETURN_FAIL("transform_io #0: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__suspension__short_read);
|
||||
}
|
||||
CHECK_STATUS("add_dictionary #6",
|
||||
wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_RAW, raw_s, workbuf));
|
||||
CHECK_STRING(read_file(&src, "test/data/brotli/romeo.txt.q11w22.br"));
|
||||
src.meta.wi = 1;
|
||||
src.meta.closed = false;
|
||||
status = wuffs_brotli__decoder__transform_io(&dec, &have, &src, workbuf);
|
||||
if (status.repr != wuffs_base__suspension__short_read) {
|
||||
RETURN_FAIL("transform_io #1: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__suspension__short_read);
|
||||
}
|
||||
status = wuffs_brotli__decoder__add_dictionary(
|
||||
&dec, WUFFS_BROTLI__DICTIONARY_TYPE_RAW, raw_s, workbuf);
|
||||
if (status.repr != wuffs_base__error__bad_call_sequence) {
|
||||
RETURN_FAIL("after start: have \"%s\", want \"%s\"", status.repr,
|
||||
wuffs_base__error__bad_call_sequence);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ---------------- Large Window and Dictionary Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// do_test_mimic_brotli_differential_with_options is like
|
||||
// do_test_mimic_brotli_differential but with the large-window quirk and
|
||||
// attached dictionaries. It sets *skipped (and returns NULL) if libbrotlidec
|
||||
// cannot attach the dictionaries: by default, it does not support serialized
|
||||
// dictionaries.
|
||||
const char* //
|
||||
do_test_mimic_brotli_differential_with_options(const char* name,
|
||||
wuffs_base__io_buffer* src,
|
||||
const char* want_filename,
|
||||
bool want_error,
|
||||
bool large_window,
|
||||
size_t dict_set,
|
||||
bool* skipped) {
|
||||
*skipped = false;
|
||||
wuffs_base__io_buffer have = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer want = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
wuffs_base__io_buffer src0 = *src;
|
||||
const char* have_status = wuffs_brotli_decode_with_options(
|
||||
&have, &src0, UINT64_MAX, UINT64_MAX, large_window, dict_set);
|
||||
|
||||
size_t num_dicts = 0;
|
||||
uint32_t dict_types[BROTLI_DICT_SPECS_MAX] = {0};
|
||||
wuffs_base__slice_u8 dicts[BROTLI_DICT_SPECS_MAX] = {0};
|
||||
CHECK_STRING(load_brotli_dict_set(dict_set, &num_dicts, dict_types, dicts));
|
||||
wuffs_base__io_buffer src1 = *src;
|
||||
int error_code = 0;
|
||||
const char* want_status = mimic_brotli_decode_with_options(
|
||||
&want, &src1, large_window, num_dicts, dict_types, dicts, &error_code);
|
||||
if (want_status == mimic_brotli_attach_dictionary_failed_message) {
|
||||
*skipped = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((have_status == NULL) != (want_status == NULL)) {
|
||||
RETURN_FAIL("%s: have \"%s\", want \"%s\" (error code %d)", name,
|
||||
have_status, want_status, error_code);
|
||||
} else if ((have_status != NULL) &&
|
||||
(brotli_c_error_code(have_status) != error_code)) {
|
||||
RETURN_FAIL("%s: have \"%s\", want error code %d", name, have_status,
|
||||
error_code);
|
||||
} else if ((have_status != NULL) != want_error) {
|
||||
RETURN_FAIL("%s: have \"%s\", want_error %d", name, have_status,
|
||||
(int)want_error);
|
||||
} else if (!want_error && (src0.meta.ri != src1.meta.ri)) {
|
||||
RETURN_FAIL("%s: ri: have %zu, want %zu", name, src0.meta.ri, src1.meta.ri);
|
||||
}
|
||||
if (want_error) {
|
||||
if (have.meta.wi > want.meta.wi) {
|
||||
have.meta.wi = want.meta.wi;
|
||||
} else {
|
||||
want.meta.wi = have.meta.wi;
|
||||
}
|
||||
}
|
||||
const char* status = check_io_buffers_equal("", &have, &want);
|
||||
if (status) {
|
||||
RETURN_FAIL("%s: %s", name, status);
|
||||
}
|
||||
|
||||
// Also check the golden file.
|
||||
if (want_filename) {
|
||||
wuffs_base__io_buffer golden = ((wuffs_base__io_buffer){
|
||||
.data = g_want_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&golden, want_filename));
|
||||
status = check_io_buffers_equal("", &have, &golden);
|
||||
if (status) {
|
||||
RETURN_FAIL("%s: golden: %s", name, status);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_brotli_decode_ext_differential() {
|
||||
CHECK_FOCUS(__func__);
|
||||
size_t n = WUFFS_TESTLIB_ARRAY_SIZE(g_brotli_ext_vectors);
|
||||
size_t num_skipped = 0;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, g_brotli_ext_vectors[i].src_filename));
|
||||
bool skipped = false;
|
||||
CHECK_STRING(do_test_mimic_brotli_differential_with_options(
|
||||
g_brotli_ext_vectors[i].src_filename, &src,
|
||||
g_brotli_ext_vectors[i].want_filename, false,
|
||||
g_brotli_ext_vectors[i].large_window,
|
||||
g_brotli_ext_vectors[i].dict_set, &skipped));
|
||||
num_skipped += skipped ? 1 : 0;
|
||||
}
|
||||
// Only the serialized dictionary files (6 of them) can be skipped.
|
||||
if (num_skipped > 6) {
|
||||
RETURN_FAIL("too many skipped: %zu", num_skipped);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_brotli_decode_ext_malformed() {
|
||||
CHECK_FOCUS(__func__);
|
||||
size_t n = WUFFS_TESTLIB_ARRAY_SIZE(g_brotli_ext_malformed);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
if (g_brotli_ext_malformed[i].src_filename) {
|
||||
CHECK_STRING(read_file(&src, g_brotli_ext_malformed[i].src_filename));
|
||||
} else {
|
||||
memcpy(src.data.ptr, g_brotli_ext_malformed[i].data,
|
||||
g_brotli_ext_malformed[i].len);
|
||||
src.meta.wi = g_brotli_ext_malformed[i].len;
|
||||
src.meta.closed = true;
|
||||
}
|
||||
char name[64];
|
||||
snprintf(name, sizeof name, "g_brotli_ext_malformed[%zu]", i);
|
||||
bool skipped = false;
|
||||
CHECK_STRING(do_test_mimic_brotli_differential_with_options(
|
||||
name, &src, NULL, true, g_brotli_ext_malformed[i].large_window,
|
||||
g_brotli_ext_malformed[i].dict_set, &skipped));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// mimic_brotli_decode_large_window adapts mimic_brotli_decode_with_options
|
||||
// to do_test_brotli_decode_large_window_far's codec_func type.
|
||||
const char* //
|
||||
mimic_brotli_decode_large_window(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
bool large_window,
|
||||
size_t dict_set) {
|
||||
if ((wlimit < UINT64_MAX) || (rlimit < UINT64_MAX) ||
|
||||
(dict_set != BROTLI_DICT_SET_NONE)) {
|
||||
return "unsupported option";
|
||||
}
|
||||
int error_code = 0;
|
||||
return mimic_brotli_decode_with_options(dst, src, large_window, 0, NULL,
|
||||
NULL, &error_code);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_mimic_brotli_decode_large_window_far() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_brotli_decode_large_window_far(
|
||||
mimic_brotli_decode_large_window, UINT64_MAX, UINT64_MAX);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Brotli Benches
|
||||
|
||||
const char* //
|
||||
@@ -1705,6 +2555,14 @@ proc g_tests[] = {
|
||||
test_wuffs_brotli_decode_truncated,
|
||||
test_wuffs_brotli_decode_workbuf_length,
|
||||
|
||||
// Large window and dictionaries.
|
||||
test_wuffs_brotli_add_dictionary,
|
||||
test_wuffs_brotli_decode_ext_all,
|
||||
test_wuffs_brotli_decode_ext_all_with_io_limits,
|
||||
test_wuffs_brotli_decode_ext_malformed,
|
||||
test_wuffs_brotli_decode_large_window_far,
|
||||
test_wuffs_brotli_decode_large_window_quirk,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_brotli_decode_alice29,
|
||||
@@ -1713,6 +2571,11 @@ proc g_tests[] = {
|
||||
test_mimic_brotli_decode_malformed,
|
||||
test_mimic_brotli_decode_romeo,
|
||||
|
||||
// Large window and dictionaries.
|
||||
test_mimic_brotli_decode_ext_differential,
|
||||
test_mimic_brotli_decode_ext_malformed,
|
||||
test_mimic_brotli_decode_large_window_far,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// Encoder tests.
|
||||
|
||||
Reference in new issue
Block a user