Repository navigation
Conversation
compile_format() replaced known atoms with %s via FORMAT_RE, then ran CLEANUP_RE to escape any remaining % as a doubled %%. A literal "%%" (the documented escape for a percent sign) was re-escaped into "%%%" -- an invalid percent-format. Every request then logged "Error in logging" with a ValueError: incomplete format. The same ordering also let the character right after a literal "%%" be consumed as the start of an atom, so "%%P" logged the process id instead of the literal text "%P". Protect literal "%%" before atom processing and restore it as a valid percent-escape after the cleanup pass. Fixes aio-libs#14390
Automation signalsActivity patterns show signs of automation. Evidence
This is an automated analysis by AgentScan |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #14586 +/- ##
=======================================
Coverage 99.13% 99.13%
=======================================
Files 135 135
Lines 54630 54642 +12
Branches 2808 2808
=======================================
+ Hits 54158 54170 +12
Misses 357 357
Partials 115 115
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Confidence Score: 4/5
[Low impact] The change is limited to literal-percent handling in built-in access logs. Safe to merge, with a non-blocking edge case affecting null separators in custom log formats. Reviews (1) · Last reviewed commit: "Fix access log format literal % escape p..." · Reviewed by Greptile |
| log_format = self.FORMAT_RE.sub(r"%s", log_format) | ||
| log_format = self.CLEANUP_RE.sub(r"%\1", log_format) | ||
| # Restore protected "%%" as a percent-format escape for a literal "%". | ||
| log_format = log_format.replace(sentinel, "%%") |
There was a problem hiding this comment.
Null separators become percent signs
If an app uses null characters to separate fields in log_format, this replacement changes them to percent signs too. For example, "%a\x00%s" now writes % between the address and status, so readers that split on null characters lose the field boundaries. Choose a marker absent from the input, or handle %% without a marker.
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Description
A literal
%%in the access logaccess_log_formatis documented as "the percent sign", but in practice a format containing it never logged anything: every request instead loggedError in loggingwith aValueError: incomplete format.AccessLogger.compile_format()replaced known atoms with%sviaFORMAT_RE, then ranCLEANUP_REto escape any remaining%as%%. A literal%%fell between the two passes:CLEANUP_REmatched the first%plus the following%and re-escaped them into%%%, which is an invalid percent-format. The same ordering also let the character right after a literal%%be consumed as the start of an atom, so%%Plogged the process id instead of the literal text%P.Fix
Protect literal
%%before atom processing and restore it as a valid percent-escape after the cleanup pass. Now%a %s 100%%compiles to%s %s 100%%and logs... 100%with no error, and%%Plogs the literal text%P.test_access_logger_formatasserted the old (buggy) compiled form for%%P; its expectation is updated, and a regression test for the literal-percent crash is added.Fixes #14390