enc/dec: add BROTLI_DCHECKs for size computation bounds (per @eustas review)#1472
enc/dec: add BROTLI_DCHECKs for size computation bounds (per @eustas review)#1472SongT-50 wants to merge 1 commit into
Conversation
b770f08 to
28d6be3
Compare
|
Sorry, I should have been more explicit - |
28d6be3 to
5b74cf3
Compare
|
Thank you for the clarification. I have updated PR v3 to use declarative-invariant form per your guidance, with bounds taken directly from your inline review of #1471:
The Notes:
Debug build ( |
|
Awesome. One more thing - we stick to C89 syntax compatibility. So BROTLI_DCHECK is not allowed before all variable declarations. I see you have added nice explanatory comments. Since we have covered why situation is safe, we could drop BROTLI_DCHECK and leave only comments. Thanks. |
…3rd review) Following @eustas's review of PR v3: > we stick to C89 syntax compatibility. So BROTLI_DCHECK is not allowed > before all variable declarations. I see you have added nice > explanatory comments. Since we have covered why situation is safe, > we could drop BROTLI_DCHECK and leave only comments. This v4 drops the 10 BROTLI_DCHECK lines that v3 placed before variable declarations (which violated C89 mixed-declarations rules). The explanatory comments documenting the invariants are kept verbatim, since they already cover why the situations are safe. Removed BROTLI_DCHECKs (10 lines, 3 files): - block_splitter_inc.h SplitByteVector: 4 (data_size <= 704, num_histograms <= 100, bitmaplen <= 13, length <= 16 MiB) - block_splitter_inc.h ClusterBlocks: 1 (num_blocks <= 16 MiB) - block_encoder_inc.h BuildAndStoreEntropyCodes: 2 (histograms_size <= 257, histogram_length_ <= 704) - dec/state.c BrotliDecoderHuffmanTreeGroupInit: 3 (alphabet_size_limit <= 1128, max_table_size <= 1504, ntrees < 1024) The block_splitter.c BROTLI_DCHECK was already removed in v3 per the maintainer's note that the situation is not possible; that comment is unchanged here. Comments preserved unchanged: each comment documents the source of the bound (RFC 7932 caps, kMaxLiteralHistograms heuristic, BROTLI_NUM_DISTANCE_SYMBOLS, etc.) so the reader can verify the invariants without needing the run-time check. Build: cmake -DCMAKE_BUILD_TYPE=Debug succeeds with no warnings or errors.
5b74cf3 to
b409ff0
Compare
|
Thanks for the C89 reminder! Removed BROTLI_DCHECK and kept the explanatory comments as you suggested. Force-pushed. |
|
Hi @eustas, Just a gentle follow-up on PR #1472 — wanted to check whether there's anything else you'd like me to address on the C89-compatible comments approach we landed on. If the current state looks good, no action needed on my end. If there are any concerns about CI status (mergeable shows UNKNOWN), I'm happy to investigate. Thanks for the careful review on this one — the back-and-forth on declarative-invariant form and C89 compatibility was very educational. Best, |
|
Hi @eustas — a gentle ping on this one. The DCHECKs are updated per your earlier review. No rush at all, but happy to rebase or address any remaining concerns whenever you have a moment. Thanks! |
Following @eustas's review of #1471: replace early-return overflow guards with
BROTLI_DCHECK assertions. This preserves the intent (document invariants) while
avoiding any runtime control-flow impact and the catastrophic-return concern.
Per reviewer suggestion: "If any of limits are hard to track, prefer BROTLI_DCHECK
to ensure them."
Changes
c/enc/block_splitter_inc.h —
FN(SplitByteVector)(2 checks):data_size * num_histogramsmultiplication boundlength * bitmaplenmultiplication boundc/enc/block_splitter_inc.h —
FN(ClusterBlocks)(1 check):num_blocks + 4 * HISTOGRAMS_PER_BATCHaddition boundc/enc/block_splitter.c —
CopyLiteralsToByteArray(1 check):insert_len + from_poswrap guardc/enc/block_encoder_inc.h —
FN(BuildAndStoreEntropyCodes)(1 check):histograms_size * histogram_length_multiplication boundc/dec/state.c —
BrotliDecoderHuffmanTreeGroupInit(3 checks):alphabet_size_limit + 376addition boundntrees * sizeof(HuffmanCode) * max_table_sizemultiplication boundntrees * sizeof(HuffmanCode*)multiplication boundBuild
Debug build (
cmake -DCMAKE_BUILD_TYPE=Debug) passes without warnings or errors.