mirror of
https://github.com/google/brotli.git
synced 2026-11-16 17:11:05 +00:00
When attaching a serialized shared dictionary (`BROTLI_SHARED_DICTIONARY_SERIALIZED`), `ParseDictionary` previously mutated `BrotliSharedDictionary` fields in-place before validating all entries and did not roll back on error. If parsing failed partway through (such as when a `context_map` entry exceeded `num_dictionaries` or when input ended before all `(words_index, transforms_index)` pairs were read), `BrotliSharedDictionaryAttach` returned `BROTLI_FALSE` while leaving the dictionary in a partially populated state. Subsequent decompression calls that proceeded after a failed attachment could then index out of bounds of `words` and `transforms` or dereference null dictionary pointers. In addition, attaching a prefix-only serialized dictionary (`num_word_lists == 0` and `num_transform_lists == 0`) onto a `BrotliSharedDictionary` that already had custom word or transform lists previously overwrote those custom tables with the built-in static dictionary. Validate `num_word_lists`, `num_transform_lists`, `num_dictionaries`, `context_based`, and `context_map` entries using local variables before committing them to `BrotliSharedDictionary` (preserving existing custom word and transform lists when appending a prefix-only serialized dictionary), and restore the prior dictionary state (freeing any newly allocated word, transform, or prefix-suffix tables) in `DecodeSharedDictionary` whenever `ParseDictionary` fails. PiperOrigin-RevId: 1021295358