Skip to content

parser: Handle too long time string on parsing#11682

Open
cosmo0920 wants to merge 2 commits intomasterfrom
cosmo0920-handle-too-long-time-on-parsing
Open

parser: Handle too long time string on parsing#11682
cosmo0920 wants to merge 2 commits intomasterfrom
cosmo0920-handle-too-long-time-on-parsing

Conversation

@cosmo0920
Copy link
Copy Markdown
Contributor

@cosmo0920 cosmo0920 commented Apr 8, 2026

If time part of the length too long for the fixed slot of parsed time element, we need to allocate a dynamic slot of parsed time element.

Closes #11665.


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

    • More reliable timestamp parsing for extremely long fractional seconds, preserving subsecond precision and avoiding crashes.
    • Safer handling of oversized timestamp inputs to prevent errors and improve stability on edge cases.
  • Tests

    • Added unit tests validating long fractional-second parsing and rejection of oversized input lengths.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88746832-3e57-4ff0-b23b-1315a9ad49c2

📥 Commits

Reviewing files that changed from the base of the PR and between 886b78c and 72665f3.

📒 Files selected for processing (2)
  • src/flb_parser.c
  • tests/internal/parser.c
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/internal/parser.c
  • src/flb_parser.c

📝 Walkthrough

Walkthrough

Updated flb_parser_time_lookup() to use a heap-allocated buffer when the fixed 64-byte stack buffer is insufficient, added overflow/alloc guards and explicit frees on all early returns, and added tests covering long fractional seconds and oversized length rejection.

Changes

Cohort / File(s) Summary
Time parser implementation
src/flb_parser.c
Replace fixed 64-byte stack buffer with selectable buf/buf_size and heap time_buf when needed; add INT_MAX/SIZE_MAX overflow checks, allocation failure handling, and ensure flb_free(time_buf) on all failure and success paths. Update strptime inputs to use buf and time_len.
Parser tests
tests/internal/parser.c
Add test_parser_time_lookup_long_fraction() and test_parser_time_lookup_reject_oversized_length(); include additional headers (math.h, float.h, limits.h) and register new tests in TEST_LIST.

Sequence Diagram(s)

(omitted — changes are localized to a single function and tests, not a multi-component flow)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #11677 — Modifies flb_parser_time_lookup() in the same file (related change addressing timezone selection for year-less timestamps).

Suggested reviewers

  • edsiper

Poem

🐰 I nibbled at a long time string,
It grew beyond my 64-byte ring,
I dug up a heap,
No more parse weep,
Now fractions dance and logs can sing 🎶

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 PR title 'parser: Handle too long time string on parsing' clearly summarizes the main change: implementing dynamic buffer allocation to handle time strings longer than the fixed buffer.
Linked Issues check ✅ Passed The PR directly addresses issue #11665 by implementing dynamic buffer allocation in flb_parser_time_lookup() to prevent 'time string length is too long' errors and adding test cases for long fractional seconds and oversized input lengths.
Out of Scope Changes check ✅ Passed All changes are focused on the parser functionality: flb_parser_time_lookup() implementation improvements in src/flb_parser.c and corresponding test additions in tests/internal/parser.c, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cosmo0920-handle-too-long-time-on-parsing

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.

@cosmo0920 cosmo0920 changed the title parser: Handle too long time on parsing parser: Handle too long time string on parsing Apr 8, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 886b78cd3c

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

Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
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.

We are experiencing a recurring parser error in Fluent Bit.

1 participant