Backport(v1.19): Optimize RFC5424 structured data parsing (#5437)#5444
Open
github-actions[bot] wants to merge 1 commit into
Open
Backport(v1.19): Optimize RFC5424 structured data parsing (#5437)#5444github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
**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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 errorsbundle exec rake test— 4,336 tests, 15,819 assertions, 0 failures, 0 errors, 3 existing pendings, 36 existing omissionsrubocop— 459 files inspected, no offensesruby -cfor both changed files andgit diff --check