Repository navigation
pack: avoid coroutine stack overflow in MessagePack JSON conversion #12313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
UgurTheG
wants to merge
8
commits into
fluent:master
from
UgurTheG:fix/pack-msgpack2json-recursion-depth-guard
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e4ec81
pack: bound msgpack2json() recursion depth to prevent stack overflow
UgurTheG ee0138b
tests: internal: pack: add msgpack2json() depth limit regression tests
UgurTheG 7baf3f7
pack: serialize nested objects without recursive stack growth
UgurTheG 335d9ed
tests: internal: cover JSON conversion on small coroutine stacks
UgurTheG 2c0ef12
tests: integration: verify nested Loki records on small stacks
UgurTheG 767e3de
pack: keep negative return for insufficient JSON buffer
UgurTheG 64d2ed6
tests: internal: pack: expect negative return on buffer overflow
UgurTheG 8d39b03
Merge branch 'master' of https://github.com/fluent/fluent-bit into fi…
UgurTheG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
tests/integration/scenarios/out_loki/config/out_loki_long_unicode.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| service: | ||
| coro_stack_size: 24576 | ||
| flush: 1 | ||
| grace: 1 | ||
| log_level: info | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: fluent/fluent-bit
Length of output: 15676
Pass the full buffer capacity to
msgpack2json().try_to_write()reserves space for the terminator withleft <= *off + str_len. For JSON output of lengthN, a buffer ofN + 1bytes must passjson_sizeasleft. Passingjson_size - 1makes the final write fail at equality and returns zero. Passingjson_sizeleaves indexNforflb_msgpack_to_json()to write the NUL terminator.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the exact-fit issue is valid, but passing
json_sizehere is not safe on its own. I checked the suggestion against the current implementation and reproduced both cases:null, four output bytes) into a five-byte buffer returns 0, although the output plus NUL should fit.abcdinto a five-byte buffer overwrites a canary atbuffer[5]with NUL. This reproduces with bothescape_unicode = FLB_FALSEandFLB_TRUE.The string writer can consume all remaining capacity and advance
offtojson_size. The closing quote then fails, butflb_msgpack_to_json()still unconditionally writesjson_str[off] = '\0', causing the one-byte out-of-bounds write.We need consistent terminator reservation across the literal and string write paths, rather than changing this argument alone. Regression coverage should require success with exactly
N + 1bytes and verify boundary canaries for undersized buffers, including strings in both Unicode modes. The existing capacity-sweep test permits a zero return at the exact-fit boundary, so it does not currently catch the unnecessary rejection. This capacity mismatch also predates the iterative traversal change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this command on a human-authored review finding. CodeRabbit findings already use the standard resolution workflow.