Skip to content

gzip: skip FCOMMENT terminator in streaming decompressor#11969

Open
saddamr3e wants to merge 1 commit into
fluent:masterfrom
saddamr3e:gzip-fcomment-terminator
Open

gzip: skip FCOMMENT terminator in streaming decompressor#11969
saddamr3e wants to merge 1 commit into
fluent:masterfrom
saddamr3e:gzip-fcomment-terminator

Conversation

@saddamr3e

@saddamr3e saddamr3e commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

The streaming gzip decompressor parses the optional header fields before handing the rest of the stream to inflate. The FNAME branch advances past the field's terminating NUL, but the FCOMMENT branch stops one byte short and leaves the comment's NUL in place. That stray byte then gets treated as the start of the deflate body (or as the FHCRC bytes), so any gzip payload that carries a comment field fails to decompress on this path. in_forward feeds network payloads through this decompressor, so a client that sets the COMMENT flag trips it. I ran into it while building a stream with a comment field and watching flb_decompress return a failure instead of the original data. Incrementing xlen the same way the FNAME branch does skips the terminator and keeps the read position aligned.


Testing

  • Example configuration file for the change
  • [N/A] Debug log output from testing the change
  • Attached unit test exercising the streaming decompressor with an FCOMMENT field
[INPUT]
    name     forward
    listen   0.0.0.0
    port     24224

[OUTPUT]
    name     stdout
    match    *

Send a forward message with compressed set to gzip where the gzip stream carries an FCOMMENT field. Added tests/internal/gzip.c:decompress_with_comment, which frames a gzip payload with a comment and runs it through flb_decompress. It fails on the unpatched tree (the decompressor returns an error and reconstructs nothing) and passes after the change.

  • [N/A] Run local packaging test showing all targets build.
  • [N/A] Set ok-package-test label to test for all targets.

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes

    • Improved gzip decompression to correctly handle gzip files with comment metadata, ensuring proper stream processing.
  • Tests

    • Added test coverage for gzip decompression with embedded comments.

Signed-off-by: saddamr3e <saddamr3e@gmail.com>
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

In flb_gzip_decompressor_process_optional_headers, the FCOMMENT field skip now increments xlen after strnlen to account for the NUL terminator, matching the FNAME skip pattern. A new test constructs a synthetic gzip stream with an injected FCOMMENT field and drives the streaming decompressor to verify correct output.

Changes

FCOMMENT skip fix and regression test

Layer / File(s) Summary
FCOMMENT byte consumption fix and decompression test
src/flb_gzip.c, tests/internal/gzip.c
xlen is incremented after strnlen so read_buffer and input_buffer_length advance past the NUL terminator when skipping FCOMMENT. The test file adds flb_compression.h, implements test_decompress_with_comment() which builds a FCOMMENT-bearing gzip stream and iteratively decompresses it, checking output matches the original data, and registers the test in TEST_LIST.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • fujimotos
  • koleini
  • edsiper

Poem

A comment was skipped, but the NUL left behind,
One byte off the mark — a bug hard to find!
Now xlen hops forward with a tiny ++,
The terminator counted, the buffer rings true.
🐇 Hops away satisfied, decompression restored!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'gzip: skip FCOMMENT terminator in streaming decompressor' directly describes the main bug fix: properly skipping the FCOMMENT field's terminating NUL byte in the gzip decompressor, which is the core change across both modified files.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/flb_gzip.c`:
- Around line 810-811: The variable `xlen` is declared as `uint16_t` but
receives values from `strnlen()` which returns `size_t`. This causes truncation
for large FCOMMENT/FNAME fields, leading to wraparound and misaligned parsing.
Change the declaration of `xlen` from `uint16_t` to `size_t` to properly handle
the full range of values returned by `strnlen()` and prevent wraparound during
the optional-header skipping logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b42eb2e-887e-401c-96ca-e3025311dffb

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf9c1b and edaae9b.

📒 Files selected for processing (2)
  • src/flb_gzip.c
  • tests/internal/gzip.c

Comment thread src/flb_gzip.c
Comment on lines +810 to +811
xlen++;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Prevent xlen wraparound in optional-header skipping

Line 810 increments xlen, but xlen is a uint16_t while strnlen() returns size_t. For long FCOMMENT/FNAME fields, truncation can under-skip bytes and misalign parsing. Use size_t for xlen.

Suggested fix
-    uint16_t                               xlen;
+    size_t                                 xlen;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/flb_gzip.c` around lines 810 - 811, The variable `xlen` is declared as
`uint16_t` but receives values from `strnlen()` which returns `size_t`. This
causes truncation for large FCOMMENT/FNAME fields, leading to wraparound and
misaligned parsing. Change the declaration of `xlen` from `uint16_t` to `size_t`
to properly handle the full range of values returned by `strnlen()` and prevent
wraparound during the optional-header skipping logic.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant