Skip to content

out_stackdriver: fix payload parsing over-reads and null safety [Backport to 4.2] - #12170

Merged
cosmo0920 merged 3 commits into
fluent:4.2from
baizhenyu:backport/stackdriver-overread-to-4.2
Jul 30, 2026
Merged

out_stackdriver: fix payload parsing over-reads and null safety [Backport to 4.2]#12170
cosmo0920 merged 3 commits into
fluent:4.2from
baizhenyu:backport/stackdriver-overread-to-4.2

Conversation

@baizhenyu

Copy link
Copy Markdown
Contributor

Backporting #12022

Backports both commits from #12022 to 4.2:

  • 88afc49d out_stackdriver: fix payload parsing over-reads and null safety
  • db8c436c out_stackdriver: reject malformed numeric subfield strings

try_assign_subfield_int() called atoll(obj.via.str.ptr) directly on a msgpack string object. msgpack strings are not NUL-terminated -- they are a pointer into the raw chunk buffer plus an explicit size -- so atoll() read past the end of the value until it happened to hit a non-digit byte. When sourceLocation.line (or a numeric httpRequest subfield) is supplied as a string, this is an out-of-bounds read that can silently corrupt the emitted integer with adjacent heap bytes.

Both cherry-picks applied cleanly. After this change all five plugins/out_stackdriver/ files are byte-identical to master.

Affected fields, all reached via try_assign_subfield_int():

Field Subfield
logging.googleapis.com/sourceLocation line
httpRequest cacheFillBytes
httpRequest requestSize
httpRequest responseSize
httpRequest status

4.2 is currently the only maintained branch below 5.0 that has had releases cut after these fixes landed on master (v4.2.7 on Jul 8, 4.2.8 on Jul 9) without picking them up. The fixes are presently only in the 5.0 line, first released in v5.0.9.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • [N/A] Example configuration file for the change
  • [N/A] Debug log output from testing the change
  • [N/A] Attached Valgrind output that shows no leaks or memory corruption was found

Covered by the runtime test sourceLocation_line_invalid_string added in db8c436c, which asserts a "123abc" line string is rejected and left at 0. Existing sourceLocation and httpRequest runtime tests cover the valid-string paths.

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

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.

Signed-off-by: Yu Yi <yiyu@google.com>
(cherry picked from commit 88afc49)
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e261fd5-055c-48fe-9eb3-f7c5e277b445

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ 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.

erain added 2 commits July 28, 2026 17:31
try_assign_subfield_int() used atoll() on the copied payload string, which
silently accepts partially-parsed input ("123abc" -> 123), treats an empty
string as 0, and would parse a truncated value from an oversized string.
Numeric httpRequest fields and sourceLocation.line could therefore be set
from malformed input.

Validate the full string with strtoll() instead: reject empty or oversized
strings up front, and only assign when the entire buffer parsed as one
complete integer (endptr at NUL) without overflow (errno). On invalid input
the field is left at its previous value.

Signed-off-by: Yu Yi <yiyu@google.com>
(cherry picked from commit db8c436)
Add a runtime test (sourceLocation_line_invalid_string) asserting that a
"123abc" sourceLocation.line string is rejected and left at 0 rather than
being partially parsed to 123.

Signed-off-by: Yu Yi <yiyu@google.com>
(cherry picked from commit db8c436)
@cosmo0920
cosmo0920 merged commit e695f76 into fluent:4.2 Jul 30, 2026
47 of 49 checks passed
zanarellidev added a commit to zanarellidev/fluent-bit that referenced this pull request Jul 31, 2026
…trings

record_get_field_uint64() and record_get_field_time() called
strtoul()/flb_strptime() directly on msgpack_object.via.str.ptr.
msgpack strings are raw, length-prefixed bytes into the decode
buffer, not NUL-terminated, so these C-string functions could read
past the field's true boundary. record_get_field_ptr()'s strncmp()
key match had the same latent issue (a key that is a prefix of
fieldname could false-match, and a short key could still be read
past its bounds by strncmp with a longer fieldname length).

A spec-compliant Kubernetes Event field (e.g. resourceVersion as a
digit-only JSON string) placed at the edge of the decode buffer is
enough to trigger an out-of-bounds read; confirmed via a guard-page
harness that reproduces EXC_BAD_ACCESS inside strtoul_l, called from
record_get_field_uint64.

This is the same bug class fixed same-day for the sibling
out_stackdriver plugin (fluent#12022, backported in fluent#12170), and the same
class that produced GHSA-5rjf-prwh-pp7q in this project before.
Applies the same fix pattern here: copy the field into a bounded,
NUL-terminated stack buffer before parsing, and require an exact
length match before the key strncmp.

A prior contributor flagged the same underlying issue in fluent#12073, but
it was self-closed without a fix landing; the vulnerable code is
still present at HEAD.

Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
zanarellidev added a commit to zanarellidev/fluent-bit that referenced this pull request Jul 31, 2026
…trings

record_get_field_uint64() and record_get_field_time() called
strtoul()/flb_strptime() directly on msgpack_object.via.str.ptr.
msgpack strings are raw, length-prefixed bytes into the decode
buffer, not NUL-terminated, so these C-string functions could read
past the field's true boundary. record_get_field_ptr()'s strncmp()
key match had the same latent issue (a key that is a prefix of
fieldname could false-match, and a short key could still be read
past its bounds by strncmp with a longer fieldname length).

A spec-compliant Kubernetes Event field (e.g. resourceVersion as a
digit-only JSON string) placed at the edge of the decode buffer is
enough to trigger an out-of-bounds read; confirmed via a guard-page
harness that reproduces EXC_BAD_ACCESS inside strtoul_l, called from
record_get_field_uint64.

This is the same bug class fixed same-day for the sibling
out_stackdriver plugin (fluent#12022, backported in fluent#12170), and the same
class that produced GHSA-5rjf-prwh-pp7q in this project before.
Applies the same fix pattern here: copy the field into a bounded,
NUL-terminated stack buffer before parsing, and require an exact
length match before the key strncmp.

A prior contributor flagged the same underlying issue in fluent#12073, but
it was self-closed without a fix landing; the vulnerable code is
still present at HEAD.

Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
zanarellidev added a commit to zanarellidev/fluent-bit that referenced this pull request Jul 31, 2026
…trings

record_get_field_uint64() and record_get_field_time() called
strtoul()/flb_strptime() directly on msgpack_object.via.str.ptr.
msgpack strings are raw, length-prefixed bytes into the decode
buffer, not NUL-terminated, so these C-string functions could read
past the field's true boundary. record_get_field_ptr()'s strncmp()
key match had the same latent issue (a key that is a prefix of
fieldname could false-match, and a short key could still be read
past its bounds by strncmp with a longer fieldname length).

A spec-compliant Kubernetes Event field (e.g. resourceVersion as a
digit-only JSON string) placed at the edge of the decode buffer is
enough to trigger an out-of-bounds read; confirmed via a guard-page
harness that reproduces EXC_BAD_ACCESS inside strtoul_l, called from
record_get_field_uint64.

This is the same bug class fixed same-day for the sibling
out_stackdriver plugin (fluent#12022, backported in fluent#12170), and the same
class that produced GHSA-5rjf-prwh-pp7q in this project before.
Applies the same fix pattern here: copy the field into a bounded,
NUL-terminated stack buffer before parsing, and require an exact
length match before the key strncmp.

A prior contributor flagged the same underlying issue in fluent#12073, but
it was self-closed without a fix landing; the vulnerable code is
still present at HEAD.

Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
edsiper pushed a commit that referenced this pull request Aug 5, 2026
…trings

record_get_field_uint64() and record_get_field_time() called
strtoul()/flb_strptime() directly on msgpack_object.via.str.ptr.
msgpack strings are raw, length-prefixed bytes into the decode
buffer, not NUL-terminated, so these C-string functions could read
past the field's true boundary. record_get_field_ptr()'s strncmp()
key match had the same latent issue (a key that is a prefix of
fieldname could false-match, and a short key could still be read
past its bounds by strncmp with a longer fieldname length).

A spec-compliant Kubernetes Event field (e.g. resourceVersion as a
digit-only JSON string) placed at the edge of the decode buffer is
enough to trigger an out-of-bounds read; confirmed via a guard-page
harness that reproduces EXC_BAD_ACCESS inside strtoul_l, called from
record_get_field_uint64.

This is the same bug class fixed same-day for the sibling
out_stackdriver plugin (#12022, backported in #12170), and the same
class that produced GHSA-5rjf-prwh-pp7q in this project before.
Applies the same fix pattern here: copy the field into a bounded,
NUL-terminated stack buffer before parsing, and require an exact
length match before the key strncmp.

A prior contributor flagged the same underlying issue in #12073, but
it was self-closed without a fix landing; the vulnerable code is
still present at HEAD.

Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
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.

4 participants