Skip to content

fix(#881): flatten control characters in pipeline/log.py's log() - #956

Merged
fdaviddpt merged 2 commits into
mainfrom
issue-881
Oct 7, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
issue-881

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

pipeline/log.py's log() wrote message to memory-*.log with no control-character flattening, unlike the shell-side equivalents (report_error() / _dispatch_report_skip(), which already run tr '[:cntrl:]' ' ' before writing -- #599/#618). An embedded newline or other control byte in a logged message -- for example an untrusted error string -- could corrupt the log line's own structure or forge what looks like a second entry.

Fixes this by adding a module-level _CONTROL_CHARS = re.compile(r"[\x00-\x1f\x7f]") (the same ASCII C0 + DEL class the shell's tr under LC_ALL=C already flattens) and applying it to message inside log() before building the line. Scoped to message only, not component, matching the shell precedent.

Three new tests in tests/test_log.py: a red-then-green assertion that a control character is flattened, a positive control proving printable text still passes through untouched, and a red-then-green assertion that an embedded newline cannot forge a second log line.

Self-review

Two reviewers ran concurrently against the fix commit.

An Explore-model reviewer found log()'s docstring hadn't been updated to describe the new flattening -- fixed in a follow-up commit. It separately observed that the issue's own framing overstates the Python-side caller count (one external caller, not 'every caller... repo-wide') -- noted, not acted on, since fixing inside log() is still the correct design regardless of count.

An oss:auditor reviewer ran a 4-class sweep and found a residual gap: three Unicode line-break codepoints outside the flattened ASCII range still read as a second line to str.splitlines() -- not a regression from the Python port (the shell tr precedent has the identical byte-wise blind spot), logged to trap.d/881.unicode-linebreaks-outside-cntrl.md for curate rather than fixed here. Since no in-repo consumer is exposed to it today, this is non-blocking.

Closes #881

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 2 commits October 7, 2026 10:02
log() wrote `message` straight into the log line with no sanitization,
unlike the shell-side report_error()/_dispatch_report_skip() equivalents,
which already run `tr '[:cntrl:]' ' '` before writing (#599/#618). An
embedded newline or other control byte in a logged message -- e.g. an
untrusted error string from pipeline/haiku.py -- could corrupt the log
line's own structure or forge what looks like a second entry.

Mirrors the shell flattening exactly: same character class (ASCII C0 plus
DEL, matching POSIX [:cntrl:] under LC_ALL=C), same replace-with-space
semantics, applied only to `message` (not `component`), inside log()
itself so every caller is covered without sanitizing independently.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…g Unicode-linebreak gap for curate

Self-review finding (Explore reviewer): log()'s docstring still described
`message` as untouched free-form text after the previous commit added
control-character flattening -- update it to say so.

Also logs a non-blocking oss:auditor finding to trap.d/: the new
`_CONTROL_CHARS` regex (ASCII C0 + DEL, mirroring the shell's
`tr '[:cntrl:]' ' '`) doesn't flatten U+0085/U+2028/U+2029, which
Python's str.splitlines() also treats as line breaks. No in-repo consumer
parses the log with splitlines() today, so this ships as a logged gap for
/oss:curate to weigh rather than widening this diff's scope.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 5b22b98 into main Oct 7, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the issue-881 branch October 7, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pipeline/log.py's log() writes control characters unflattened, unlike the shell-side equivalents

1 participant