Skip to content

Fix #84: Failure in brotli_uncompress_add() is not propagated to the user#85

Merged
kjdev merged 1 commit into
kjdev:masterfrom
ndossche:fix-84
May 27, 2026
Merged

Fix #84: Failure in brotli_uncompress_add() is not propagated to the user#85
kjdev merged 1 commit into
kjdev:masterfrom
ndossche:fix-84

Conversation

@ndossche
Copy link
Copy Markdown
Contributor

@ndossche ndossche commented May 26, 2026

Crucially, must check against hard errors
(BROTLI_DECODER_RESULT_ERROR) not against
BROTLI_DECODER_RESULT_SUCCESS because then NEEDS_MORE_INPUT is misinterpreted as error.

Note: this was found by a hybrid static-dynamic analyzer I'm developing.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and reporting for Brotli decompression operations. The system now properly detects and emits warnings when decompression errors occur, while ensuring proper resource cleanup in all scenarios.

Review Change Stack

… the user

Crucially, must check against hard errors
(`BROTLI_DECODER_RESULT_ERROR`) not against
`BROTLI_DECODER_RESULT_SUCCESS` because then `NEEDS_MORE_INPUT` is
misinterpreted as error.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5064e29-cc33-4ab9-a355-5047c089d1b6

📥 Commits

Reviewing files that changed from the base of the PR and between 40c7526 and 987ad82.

📒 Files selected for processing (1)
  • brotli.c

📝 Walkthrough

Walkthrough

The PR modifies brotli_uncompress_add to properly handle Brotli decoder errors. It reorders cleanup by freeing the input buffer before checking the decoder result, adds explicit error detection for BROTLI_DECODER_RESULT_ERROR, and returns FALSE when decoding fails instead of returning output unconditionally.

Changes

Brotli decompression error handling

Layer / File(s) Summary
Decoder error checking and cleanup reordering
brotli.c
brotli_uncompress_add frees the input buffer before evaluating decoder outcome and explicitly checks for BROTLI_DECODER_RESULT_ERROR, emitting a warning, freeing output, and returning FALSE on failure. Previously, output was returned unconditionally before buffer cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • kjdev/php-ext-brotli#84: This PR directly addresses the failure-propagation problem by adding explicit decoder error detection and returning FALSE instead of unconditionally returning output.

Possibly related PRs

  • kjdev/php-ext-brotli#83: Both PRs modify error handling and cleanup in brotli_uncompress_add, with PR #83 introducing smart_str output and this PR adding explicit decoder-error checking before returning.

Poem

🐰 A buffer freed, an error caught,
No more confusion, no more thought—
When Brotli falters, speak it true,
Return FALSE, not garbled goo!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: fixing error propagation in brotli_uncompress_add() to properly detect and report failures to users.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kjdev kjdev merged commit 415c2bd into kjdev:master May 27, 2026
90 checks passed
@kjdev
Copy link
Copy Markdown
Owner

kjdev commented May 27, 2026

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants