dec: core security hardening against memory validation and resource flaws#1497
Open
owvr27 wants to merge 2 commits into
Open
dec: core security hardening against memory validation and resource flaws#1497owvr27 wants to merge 2 commits into
owvr27 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Hardening Changes
This unified patch introduces production-grade defensive validations across the decoder core (
c/dec/decode.c,c/dec/huffman.c, andc/dec/state.c) to eliminate five distinct resilience and memory boundaries gaps surfaced via dense stream state anomalies:table_budgetconstraint parameter insideBrotliBuildHuffmanTableto halt multi-level accumulation before breaching array structures, accompanied by a strict trailingslab_endrange-check insideHuffmanTreeGroupDecodeto insulate against heap OOB writes.BrotliCalculateRingBufferSizecalculations to precise unsigned arithmetic to completely eliminate undefined behavior (UB) on large window configurations (e.g.,window_bits = 30), forcing saturation thresholds atwindow_sizeto block unconstrained 1 GiB OOM allocation logic vectors.rb_roundtrips == 0to safeguard uninitialized heap buffers from flushing to the output context.s->loop_counterupon transitioning intoBROTLI_STATE_METABLOCK_DONEstates, cutting off intermediate state leakages during streaming boundary suspensions, backed by a defensive invariant verificationBROTLI_DCHECKat function entries.num_literal_htreesvalues against logically reachable context mapping indices, and deploys global multiplication overflow validation protections prior to executing internal memory allocation macros withinBrotliDecoderHuffmanTreeGroupInit.Verification
All modifications maintain full API integration limits and seamlessly route violations into existing error blocks (
BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE, etc.) without introducing custom public API disruptions. Structural verification confirms no degradation against standard high-performance decoding hot paths (s->rb_roundtrips > 0).