utils: fix SIMD boundary for JSON string encoding - #12285
Conversation
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe SIMD string writers now stop vector processing at complete vectors. Internal, runtime, and integration tests cover long Unicode JSON payloads through Loki output formatting and HTTP ingestion. ChangesUnicode and Loki boundary handling
Merge Risk: ⚪ Minimal · up to This change prevents JSON encoders from including bytes beyond the declared string boundary and adds targeted regression and Loki coverage. No actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3710135f56
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
Fix JSON string corruption caused by SIMD reads crossing the declared end of long strings after processing multibyte UTF-8 characters.
Affected strings could receive 1–15 bytes of adjacent memory on 16-byte SIMD platforms, or fewer bytes with narrower SIMD implementations. Loki JSON output with
remove_keysmade the issue especially reproducible and could expose fragments of other log records.Root cause
The JSON string writers rounded
str_lendown to a SIMD-aligned boundary and usedi < vlento decide whether another vector could be processed.After scalar processing of a 2–4-byte UTF-8 sequence,
imay no longer be SIMD-aligned. Consequently,i < vlendid not guarantee that the complete vector remained withinstr_len, allowing bytes past the logical end of the string to be read and copied.Changes
Require the entire SIMD vector to fit within the remaining input:
Apply the correction to both escaped and raw JSON string writers.
Add an internal regression test with poisoned bytes after the declared input boundary.
Cover SIMD-width, 24 KiB, and 36 KiB payload sizes.
Add Loki runtime coverage using JSON line formatting and
remove_keys.Add an end-to-end integration test that sends 200 approximately 40 KiB Unicode records through tail → Loki and compares every decoded message with its original value.
Compatibility
No configuration or API changes. The only behavioral change is that bytes beyond the declared string length are no longer included in encoded output.
Verification
Recorded in the referenced task, “Fix JSON string corruption”:
cmake --build build --target flb-it-utils -j8— passed./build/bin/flb-it-utils write_str_simd_boundary— passedctest --test-dir build -R '^flb-it-utils$' --output-on-failure— passedThe latest Loki runtime and new Python integration tests still need final functional and macOS Leaks runs before submitting the PR.
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:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-testlabel to test for all targets (requires maintainer to do).Documentation
Backporting
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
Tests