Skip to content

Optimize RFC5424 structured data parsing - #5437

Merged
kenhys merged 1 commit into
fluent:masterfrom
oiahoon:fix/rfc5424-regexp-backtracking
Jul 17, 2026
Merged

Optimize RFC5424 structured data parsing#5437
kenhys merged 1 commit into
fluent:masterfrom
oiahoon:fix/rfc5424-regexp-backtracking

Conversation

@oiahoon

@oiahoon oiahoon commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Fixes #5367

What this PR does / why we need it:

The RFC5424 structured-data pattern repeated an element that already contains a lazy wildcard. On Ruby 3.2 and older, invalid input with adjacent structured-data elements could trigger exponential backtracking.

This removes the redundant outer repetition. The lazy match still spans adjacent structured-data elements, while a focused timeout regression protects the invalid-suffix case.

Validation included an exhaustive comparison of 97,656 generated suffixes on Ruby 2.6 and Ruby 4.0; match results and all named captures were unchanged.

Docs Changes:

None.

Release Note:

parser_syslog: avoid excessive backtracking when parsing malformed RFC5424 structured data.

Testing:

  • bundle exec ruby -Itest test/plugin/test_parser_syslog.rb — 77 tests, 332 assertions, 0 failures, 0 errors
  • bundle exec rake test — 4,336 tests, 15,819 assertions, 0 failures, 0 errors, 3 existing pendings, 36 existing omissions
  • rubocop — 459 files inspected, no offenses
  • ruby -c for both changed files and git diff --check

Signed-off-by: Joey@macstudio <4296411@qq.com>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Watson1978 Watson1978 added this to the v1.20.0 milestone Jul 17, 2026
@Watson1978 Watson1978 added the backport to v1.19 We will backport this fix to the LTS branch label Jul 17, 2026

@kenhys kenhys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: it's not scope of this PR, it will accept invalid RFC5424 literal - "[sd-data 1]garbage[sd-data 2]".
anyway this change itself seems to be good.

@kenhys
kenhys merged commit f380d99 into fluent:master Jul 17, 2026
24 checks passed
Watson1978 pushed a commit that referenced this pull request Jul 21, 2026
)

**Which issue(s) this PR fixes**:
Fixes #5367

**What this PR does / why we need it**:

The RFC5424 structured-data pattern repeated an element that already
contains a lazy wildcard. On Ruby 3.2 and older, invalid input with
adjacent structured-data elements could trigger exponential
backtracking.

This removes the redundant outer repetition. The lazy match still spans
adjacent structured-data elements, while a focused timeout regression
protects the invalid-suffix case.

Validation included an exhaustive comparison of 97,656 generated
suffixes on Ruby 2.6 and Ruby 4.0; match results and all named captures
were unchanged.

**Docs Changes**:

None.

**Release Note**:

parser_syslog: avoid excessive backtracking when parsing malformed
RFC5424 structured data.

**Testing**:

- `bundle exec ruby -Itest test/plugin/test_parser_syslog.rb` — 77
tests, 332 assertions, 0 failures, 0 errors
- `bundle exec rake test` — 4,336 tests, 15,819 assertions, 0 failures,
0 errors, 3 existing pendings, 36 existing omissions
- `rubocop` — 459 files inspected, no offenses
- `ruby -c` for both changed files and `git diff --check`

Signed-off-by: Joey@macstudio <4296411@qq.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: onice <joyhuangyuyao@gmail.com>
@Watson1978 Watson1978 added the backported "backport to LTS" is done label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch backported "backport to LTS" is done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parser_syslog: Optimize RFC5424 regex

3 participants