Repository navigation
fix: keep signature-identified binaries binary instead of guessing UTF-16 - #198310
qingminglong wants to merge 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. What this changesThe PR prevents recognized binary attachment types from falling through to UTF-16 text inference. Example: Send a NUL-padded SQLite database named t.db with application/octet-stream metadata.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 3 items remain This PR addresses a real attachment bug, but its guard also rejects recoverable text MIME hints; an existing extraction regression fails in CI. Priority: P1 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe shared media-core classifier combines attachment bytes and MIME hints into one classification consumed by extraction and inbound document-context rendering. flowchart TD
A[Attachment bytes and metadata] --> B[MIME detection]
B --> C[Shared attachment classifier]
C --> D[Text and PDF extraction]
C --> E[Unsupported format marker]
D --> F[Agent document context]
E --> F
Technical reviewBest possible solution: Keep binary-signature precedence in the shared classifier while preserving text recovery for metadata-only MIME hints and tracking unknown-binary handling separately. Do we have a high-confidence way to reproduce the issue? The linked report provides an official-release SQLite reproduction, and current-main source exposes the same fall-through; no target code was executed during this read-only review. Is this the best way to solve the issue? The shared classifier is the correct repair owner, but a resolved MIME is not necessarily a byte signature, so the guard needs a narrower condition. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 25559c477004. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +8, Tests +47. Total +55 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 13, 2026, 9:47 AM ET / 14:47 UTC. |
|
Thanks @qingminglong for working on #198289. We landed #198309 (afa871c), the earliest of the three fixes, which keeps an attachment binary when its magic bytes match the resolved type and leaves the BOM, extension and text-hint paths unchanged. Closing this one as a duplicate; your work helped confirm the cause. |
|
Rebased onto current
Root cause. A malformed Fix. Require a well-formed
|
Closes #198289
What Problem This Solves
Fixes: binary attachments are decoded as UTF-16 text and ~60,000 characters of garbage are inlined into the model prompt when the file carries a NUL-heavy byte signature (SQLite, ELF, PE, Java class, OTF, WASM).
User Impact
A database backup, executable, or font sent as an attachment now reaches the model as an unsupported binary reference instead of a wall of decoded garbage, so the turn is answered normally instead of being refused. No configuration change, migration, or user action is required.
Why This Change Was Made
classifyAttachmentBytesfell through to a text re-sniff for every payload that did not resolve to a text MIME. In that branchresolveUtf16Charsetderivesutf-16le/utf-16befrom the NUL ratio alone, so a SQLite header followed by page padding read as UTF-16 and was decoded into printable-looking characters. A MIME that already classifies asbinaryis a magic-byte verdict about the payload, not an extension guess, so the classifier now returnsbinaryfor it and leaves only the BOM case to the decoder branch. Byte-detected archives keeparchive, and genuine BOM-prefixed UTF-16 text still reaches the decoder.Evidence
Regression test red→green:
magic-byte binary signatures outrank a NUL-driven UTF-16 guess(7 cases: SQLite, SQLite behind a.txtname, ELF, PE, Java class, OTF, WASM). With the fix reverted the file reportsTests 7 failed | 14 passed (21); with the fix applied it reportsTests 21 passed (21)in 5.06 s.Targeted suite:
node scripts/run-vitest.mjs run packages/media-core/src/attachment-classify.test.ts→Test Files 1 passed (1),Tests 21 passed (21). The 14 pre-existing classification cases (UTF-8 truncation, UTF-16 with/without BOM, PNG, ZIP, octet-stream, YAML allowlist) are unchanged and still pass.Behavior verification,
classifyAttachmentBytes({ declaredMime: "application/octet-stream", name: "*.db" })before → after:text/plain,utf-16leapplication/x-sqlite3,binarytext/plain,utf-16leapplication/x-elf,binarytext/plain,utf-16befont/otf,binarytext/plain,utf-16leapplication/x-msdownload,binarytext/plain,utf-16leapplication/java-vm,binarytext/plain,utf-16leapplication/wasm,binaryoxlinton both changed files: 0 warnings, 0 errors.oxfmt --check: clean.tsgo -p tsconfig.core.json: 64 errors on this branch and 64 on the parent commit — identical count, all from a pre-existing@babel/types7/8 duplicate in this local install, and none of them namesattachment-classifyormedia-core. Verified withgrep -c 'error TS'on both sides plusgrep -c attachment-classify→ 0.Scope: only
packages/media-core/src/attachment-classify.ts(+8 lines) and its test file (+47 lines). The downstream document-context renderer, the MIME sniffer, and thefile-typedependency are untouched.This proves the classifier no longer converts signature-identified binaries into text. It does not prove the end-to-end prompt size on a live gateway, which depends on the existing
[Unsupported document format]path in the inbound document context.