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:
Claude committed 2026-10-26 23:59:14 +00:00
commit d74d28bef9
42 files changed
+4220 -461

No files matched your search

+72
View File
@@ -158,3 +158,75 @@ cleanup:
BrotliEncoderDestroyInstance(state);
return ret;
}
// ---------------- Large Window and Dictionaries
#include "brotli/shared_dictionary.h"
// mimic_brotli_decode_with_options is like mimic_brotli_decode_error_code but
// it also sets BROTLI_DECODER_PARAM_LARGE_WINDOW (if large_window is true) and
// attaches dictionaries (with BrotliDecoderAttachDictionary). Each
// dict_types[i] is a BrotliSharedDictionaryType value: 0 for
// BROTLI_SHARED_DICTIONARY_RAW and 1 for BROTLI_SHARED_DICTIONARY_SERIALIZED.
//
// libbrotlidec only supports serialized dictionaries when built with
// BROTLI_EXPERIMENTAL (which is not the default). When attaching a dictionary
// fails, this function returns
// mimic_brotli_attach_dictionary_failed_message.
const char mimic_brotli_attach_dictionary_failed_message[] =
"libbrotlidec: BrotliDecoderAttachDictionary failed";
const char* //
mimic_brotli_decode_with_options(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
bool large_window,
size_t num_dicts,
const uint32_t* dict_types,
const wuffs_base__slice_u8* dicts,
int* error_code_ptr) {
*error_code_ptr = 0;
BrotliDecoderState* state = BrotliDecoderCreateInstance(NULL, NULL, NULL);
if (!state) {
return "libbrotlidec: BrotliDecoderCreateInstance failed";
}
if (large_window &&
!BrotliDecoderSetParameter(state, BROTLI_DECODER_PARAM_LARGE_WINDOW,
1u)) {
BrotliDecoderDestroyInstance(state);
return "libbrotlidec: BrotliDecoderSetParameter failed";
}
for (size_t i = 0; i < num_dicts; i++) {
if (!BrotliDecoderAttachDictionary(
state, (BrotliSharedDictionaryType)dict_types[i], dicts[i].len,
dicts[i].ptr)) {
BrotliDecoderDestroyInstance(state);
return mimic_brotli_attach_dictionary_failed_message;
}
}
size_t avail_in = wuffs_base__io_buffer__reader_length(src);
const uint8_t* next_in = wuffs_base__io_buffer__reader_pointer(src);
size_t avail_out = wuffs_base__io_buffer__writer_length(dst);
uint8_t* next_out = wuffs_base__io_buffer__writer_pointer(dst);
size_t total_out = 0;
BrotliDecoderResult result = BrotliDecoderDecompressStream(
state, &avail_in, &next_in, &avail_out, &next_out, &total_out);
*error_code_ptr = (int)BrotliDecoderGetErrorCode(state);
BrotliDecoderDestroyInstance(state);
src->meta.ri += wuffs_base__io_buffer__reader_length(src) - avail_in;
dst->meta.wi += wuffs_base__io_buffer__writer_length(dst) - avail_out;
switch (result) {
case BROTLI_DECODER_RESULT_SUCCESS:
return NULL;
case BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:
return "libbrotlidec: needs more input";
case BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:
return "libbrotlidec: needs more output";
default:
break;
}
return "libbrotlidec: BrotliDecoderDecompressStream failed";
}