ppkarwasz opened a new issue, #4460:
URL: https://github.com/apache/logging-log4j2/issues/4460
The HTML format of `%enc{pattern}{HTML}` (also the default of
`%enc{pattern}`) is implemented in
`EncodingPatternConverter.EscapeFormat.HTML#escape` as two passes: the first
pass appends padding for the escape sequences, the second walks backward and
writes each character or its escape sequence into place. The second pass writes
escape sequences with `StringBuilder.replace(start, end, str)`, which shifts
the whole tail of the buffer on every call, even though the replacement has the
same length as the replaced region. Escaping a value with k special characters
therefore costs O(n·k) instead of O(n), and the comment "do this in two passes
to keep O(n) time complexity" does not hold for this format.
Measured on 2.26.1 with a message consisting only of `"` characters: 27 ms
for 32 KiB, 97 ms for 64 KiB, 307 ms for 128 KiB, roughly quadrupling each time
the input doubles. The XML format produces output of the same size in 3–8 ms,
because it delegates to the linear `StringBuilders.escapeXml`. The CRLF and
JSON formats are not affected.
The effect is bounded by the size of the values the application logs: at
typical field sizes the overhead is a few milliseconds. This issue originates
from a private security report classified as a bug.
Fix: write escape sequences character by character with `setCharAt`, as the
`CRLF` format already does, and add a test comparing the output of the HTML
format for a long value of special characters with the expected escaped string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]