Skip to content

input_chunk: input_log: in_storage_backlog: address underflowing / overflowing chunk limit size - #12299

Open
cosmo0920 wants to merge 4 commits into
masterfrom
cosmo0920-address-underflowing-chunk-limit-size
Open

input_chunk: input_log: in_storage_backlog: address underflowing / overflowing chunk limit size#12299
cosmo0920 wants to merge 4 commits into
masterfrom
cosmo0920-address-underflowing-chunk-limit-size

Conversation

@cosmo0920

@cosmo0920 cosmo0920 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Implemented general filesystem chunk-accounting guards.

  • fs_chunks_size now uses saturating subtraction: underflow logs a warning and resets the counter to zero instead of wrapping near SIZE_MAX.
  • Additions are overflow-checked and saturate at SIZE_MAX.
  • Chunk-size adjustments remain signed, so negative trim deltas correctly subtract rather than becoming huge unsigned additions.
  • Per-record routing paths use the centralized guard.
  • fs_backlog_chunks_size has equivalent guards and subtracts the size recorded when the backlog entry was created.
  • Added regression coverage for subtraction underflow, negative adjustments, and addition overflow in input_chunk_routes.c.

Verification:

  • cmake --build build --target fluent-bit-bin flb-it-input_chunk_routes — passed.
  • ctest --test-dir build -R '^flb-it-input_chunk_routes$' --output-on-failure — 1 passed.
  • .venv\Scripts\python.exe -m pytest scenarios/in_forward/tests/test_in_forward_001.py -q -k storage_limit — 2 passed, 1 platform skip.
  • .venv\Scripts\python.exe -m pytest scenarios/in_storage_backlog/tests/test_in_storage_backlog_001.py -q — 2 passed, 2 platform skips.
  • git diff --check — passed.

Closes #12220.


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:

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

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

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

Documentation

  • 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 filesystem backlog size accounting to prevent underflow and overflow.
    • Added safeguards for invalid or negative chunk-size adjustments.
    • Counters now clamp safely at zero or saturate at the maximum supported value, with warnings for inconsistent values.
    • Improved accounting reliability when chunks are removed or routed through outputs.
  • Tests

    • Added coverage verifying safe counter decrements and overflow handling.

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>
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ca9b0eb-5f0e-43fc-9c1e-df5eed743230

📥 Commits

Reviewing files that changed from the base of the PR and between 6315162 and 2dd1c8f.

📒 Files selected for processing (5)
  • include/fluent-bit/flb_input_chunk.h
  • plugins/in_storage_backlog/sb.c
  • src/flb_input_chunk.c
  • src/flb_input_log.c
  • tests/internal/input_chunk_routes.c

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change adds bounded filesystem chunk accounting for input outputs and storage backlog. Signed chunk-size deltas prevent invalid negative-size calculations. Routing, cleanup, eviction, and backlog updates now use guarded subtraction and saturating addition. Regression coverage validates these cases.

Changes

Chunk accounting safety

Layer / File(s) Summary
Accounting contracts and safeguards
include/fluent-bit/flb_input_chunk.h, src/flb_input_chunk.c
Adds the subtraction API, changes chunk updates to signed sizes, and adds overflow- and underflow-safe accounting helpers.
Accounting call sites
src/flb_input_chunk.c, src/flb_input_log.c, plugins/in_storage_backlog/sb.c
Uses guarded subtraction for chunk removal paths and saturates counters when additions exceed SIZE_MAX.
Accounting regression coverage
tests/internal/input_chunk_routes.c
Tests normal updates, underflow protection, oversized subtraction, saturation, and fs_counted state.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 2dd1c

The change prevents chunk-size accounting from wrapping during underflow or overflow and keeps negative adjustments subtractive; no actionable merge-blocking risk remains after normal checks and review.

Possibly related issues

Possibly related PRs

Suggested reviewers: edsiper

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% 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 clearly identifies the affected components and the primary underflow and overflow fix.
Linked Issues check ✅ Passed The changes address issue #12220 by preventing counter underflow, preserving signed adjustments, and adding regression coverage.
Out of Scope Changes check ✅ Passed All changes support filesystem chunk-accounting protection and related regression tests; no unrelated code changes are evident.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-address-underflowing-chunk-limit-size

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dd1c8f4b5

ℹ️ 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".

Comment thread src/flb_input_chunk.c
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.

input chunk: "no available chunk" while storage is almost empty (fs_chunks_size underflow)

1 participant