fix(tui,coding-agent): survive lone surrogates in table cells and terminate the WebP EXIF scan - #2033
Open
snimu wants to merge 4 commits into
Open
fix(tui,coding-agent): survive lone surrogates in table cells and terminate the WebP EXIF scan#2033snimu wants to merge 4 commits into
snimu wants to merge 4 commits into
Conversation
…minate the WebP EXIF scan encodeURIComponent throws URIError on a lone UTF-16 surrogate, so table cell markers sanitize content with toWellFormed before encoding. The WebP RIFF scan read chunk sizes with signed 32-bit arithmetic; a high-bit size walked the scan backward forever, hanging the process on a corrupt or crafted image. Chunk sizes (and the little-endian TIFF read32) are now unsigned.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4410455. Configure here.
…test runner packages/tui tests run via node --test, not vitest; the lone-surrogate pin now uses node:test and the vitest include-list change is reverted.
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.

Summary
Two rendering-input crashes:
encodeURIComponent, which throwsURIError: URI malformedon a lone surrogate (e.g. text split mid-astral-character at a cell boundary) — taking down the whole TUI render. Content is now sanitized withtoWellFormed()(available on every supported runtime, Node ≥ 20) so the surrogate becomes U+FFFD and the marker round-trips. Fixes the defect reported in discussion [Bug] TUI crashes with URIError in cellMarker when rendering markdown tables #2001.read32, which had the same signedness bug — are now read unsigned, guaranteeing forward progress. Fixes the defect reported in discussion A malformed WebP chunk size hangs the agent forever: RIFF size decoded with a signed shift #1554.Validation
URIError), and a WebP whose chunk size re-visits its own offset terminates (pre-fix: infinite loop — the unfixed run had to be killed after 20s)packages/tuivitest include list gains the new selection-metadata suite (the package runs an explicit whitelist)npm run checkpasses via the pre-commit hookLOC
Total src: +6/−3 (net +3); tests: +35/−0 (net +35).
Src +7/−3 (both point fixes, no new mechanism). Tests +34, changelog 2 fragments, 1 vitest include line.
Linear: RES-1266 https://linear.app/primeintellect/issue/RES-1266
Note
Low Risk
Targeted defensive fixes in rendering metadata and binary parsing; behavior only changes for previously crashing or hanging malformed inputs.
Overview
Fixes two input-handling failures in the TUI and image EXIF path.
Table selection markers no longer throw when cell content includes a lone UTF-16 surrogate.
cellMarkerruns content throughtoWellFormed()beforeencodeURIComponent, so malformed sequences become U+FFFD and markers still round-trip through extraction.WebP EXIF orientation no longer hangs on corrupt or crafted files. Chunk sizes and little-endian TIFF
read32values are coerced with>>> 0so high-bit sizes are not treated as negative offsets that move the RIFF scan backward in a loop; the scan exits and orientation falls back to default instead.Reviewed by Cursor Bugbot for commit a3d1139. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix WebP EXIF scan termination and lone-surrogate handling in TUI selection markers
readOrientationFromTiffandfindWebpTiffOffsetnow treat offsets/sizes with the high bit set as large unsigned values rather than negative; malformed inputs that previously errored early via negative-offset paths will instead be caught by existing bounds checks.Macroscope summarized a3d1139.