Skip to content

Fix quadratic complexity in HTML pattern escaping - #4461

Merged
ramanathan1504 merged 5 commits into
apache:2.xfrom
vitoriabentes:fix/2.x/html-escape-performance
Nov 7, 2026
Merged

ramanathan1504 merged 5 commits into
apache:2.xfrom
vitoriabentes:fix/2.x/html-escape-performance

Conversation

@vitoriabentes

Copy link
Copy Markdown
Contributor

Fixes #4460.

HTML escaping in EncodingPatternConverter used StringBuilder.replace for each special character, shifting the rest of the buffer each time. This made escaping inputs with many special characters quadratic. This change writes escape sequences in place and adds a test for a large input.

Testing:

  • mvn -pl log4j-core-test -am '-Dtest=EncodingPatternConverterTest' '-Dsurefire.failIfNoSpecifiedTests=false' test — passed.

@ramanathan1504

Copy link
Copy Markdown
Contributor

The setCharAt loop in EncodingPatternConverter writes each escape in place, so the HTML pass is linear now.
Can you add a changelog entry in src/changelog/.2.x.x/ for #4460, with a second issue line linking this PR?

@ramanathan1504 ramanathan1504 added bug Incorrect, unexpected, or unintended behavior of existing code performance Issues or PRs that affect performance, throughput, latency, etc. port-to-main labels Nov 6, 2026
vitoriabentes and others added 2 commits November 6, 2026 10:57
…ttern/EncodingPatternConverterTest.java

Co-authored-by: Ramanathan Muthu <ramanathanbscmca@gmail.com>
@ramanathan1504

ramanathan1504 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

The changelog entry is still missing. Can you add it in src/changelog/.2.x.x/

@ramanathan1504 ramanathan1504 added java Pull requests that update Java code layouts Affects one or more Layout plugins labels Nov 7, 2026
@ramanathan1504 ramanathan1504 added this to the 2.27.0 milestone Nov 7, 2026

@ramanathan1504 ramanathan1504 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 for the contribution

@ramanathan1504 ramanathan1504 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.

Pushed the removal of the unused Timeout import so spotless:check passes.

@ramanathan1504
ramanathan1504 enabled auto-merge (squash) November 7, 2026 15:18
@ramanathan1504
ramanathan1504 merged commit df5fee4 into apache:2.x Nov 7, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Merged in Log4j pull request tracker Nov 7, 2026
@ramanathan1504 ramanathan1504 modified the milestones: 2.27.0, 2.26.2 Nov 8, 2026
ramanathan1504 added a commit that referenced this pull request Nov 9, 2026
* Fix quadratic complexity in HTML pattern escaping
---------

Co-authored-by: Ramanathan <ramanathan@apache.org>
(cherry picked from commit df5fee4)
@ramanathan1504 ramanathan1504 removed this from the 2.26.2 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Incorrect, unexpected, or unintended behavior of existing code java Pull requests that update Java code layouts Affects one or more Layout plugins performance Issues or PRs that affect performance, throughput, latency, etc. port-to-2.26.x port-to-main

Projects

Development

Successfully merging this pull request may close these issues.

%enc{...}{HTML} escaping is quadratic in the number of escaped characters

2 participants