Repository navigation
Conversation
log() (scripts/log.sh) wrote its message argument verbatim into the daily log file, with no newline handling. Several call sites in scripts/save-session.sh embed the first 80 bytes of a model's reply straight into a log line -- untrusted text since #593 -- and an embedded newline landed at column 0 of the log file, reading as a second, forged log entry to anything parsing the log. Flattened once, inside log() itself, rather than at each of the (at least three) call sites that embed such text, so the class is closed everywhere log() is used rather than only at the newest call site. Co-Authored-By: Max <noreply>
…ollow-up) Self-review (Explore + oss:auditor) on the first #599 commit found that `tr '[:cntrl:]'` under the caller's own UTF-8 locale errors on a byte sequence truncated mid-multibyte-character -- exactly what save-session.sh's `head -c 80` cuts of a model reply produce whenever the 80-byte offset lands inside a multibyte character. `tr` then prints "Illegal byte sequence", exits nonzero, and truncates its own output at the bad byte, silently dropping everything logged after it -- and because save-session.sh runs under `set -e`, the `message=$(...)` assignment's nonzero exit aborts the whole script on an otherwise ordinary non-English model reply (legitimate since #593). `LC_ALL=C` makes tr classify every byte 0-255 on its own, identically on GNU and BSD, so the embedded-newline/CR/tab class this fix exists to close is still caught while a non-ASCII byte that is not itself a control code passes through untouched instead of erroring. New test test_truncated_multibyte_reply_does_not_abort_or_lose_the_tail pins this: red without LC_ALL=C (script aborts, content lost), green with it. Co-Authored-By: Max <noreply>
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.
What
log() (scripts/log.sh) wrote its message argument verbatim into the daily log
file, with no newline handling. Several call sites in
scripts/save-session.sh embed the first 80 bytes of a model's reply straight
into a log line -- untrusted text since #593 -- and an embedded newline
landed at column 0 of the log file, reading as a second, forged log entry to
anything parsing the log.
Approach
Sanitize once, inside log() itself, rather than at each of the (at least
three) call sites that embed such text, so the class is closed everywhere
log() is used rather than only at the newest call site.
Follow-up commit: self-review (Explore + oss:auditor) found that
tr '[:cntrl:]'under the caller's own UTF-8 locale errors on a bytesequence truncated mid-multibyte-character -- exactly what save-session.sh's
head -c 80cut of a model reply produces whenever the 80-byte offset landsinside a multibyte character.
trthen exits nonzero and truncates its ownoutput at the bad byte, and because save-session.sh runs under
set -e, themessage=$(...)assignment's nonzero exit aborted the whole script on anotherwise ordinary non-English model reply.
LC_ALL=Cmakes tr classifyevery byte 0-255 on its own, identically on GNU and BSD, so the
embedded-newline/CR/tab class this fix exists to close is still caught while
a non-ASCII byte that is not itself a control code passes through untouched.
Verification
sanitization of embedded control bytes, and
test_truncated_multibyte_reply_does_not_abort_or_lose_the_tail (red without
LC_ALL=C: script aborts, content lost; green with it).
Changelog
changelog.d/599.fixed.md added.
Closes #599
This PR was assembled by a maintainer tick from two already-committed and
pushed commits (a developer lane dispatched in a prior tick whose handback
never opened the pull request) -- the commit messages above are that
developer's own record of the work and its self-review.
🤖 Generated with Claude Code
https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
[AI-generated]