Skip to content

fix(files): never open a remote binary as text, and never page one in to find out - #34877

Merged
nwparker merged 1 commit into
mainfrom
nwparker/remote-file-read-binary-sniff
Oct 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/remote-file-read-binary-sniff

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

ELI5

When you open a file on a WSL host, an SSH host or a paired server, the server decided whether it was binary by its file extension alone. A binary with an extension the list didn't know (.so, .o, .wasm, .class and so on) was sent as text. A small one opened in the editor as garbled text, and saving it would write the garbage back. A large one (up to 50 MB) was downloaded in full before the desktop noticed it was binary. Now the server checks the file's first bytes, and the desktop shows such files as binary immediately.

What Changed

  • Before:
    • files.read checked only the extension list (isMobileBinaryPath).
    • An unlisted binary under 512 KiB came back as { content, truncated: false }, and the editor opened it as editable text.
    • Between 512 KiB and 50 MiB, the desktop paged the whole file in 384 KiB chunks before its NUL check called it binary.
  • After:
    • Host (readLocalMobileFile in src/main/runtime/files/file-reads.ts): checks the prefix it already reads for a NUL byte in the first 8 KiB (isBinaryBuffer, git's own heuristic). If it finds one, it answers the existing binary_file refusal.
    • Desktop (readRuntimeFileContent, readRemoteBinaryFile):
      • A binary_file refusal for a file with nothing to preview (not an image or PDF) shows as binary at once, with no preview fetch and no paging.
      • Text from an older host whose first 8 KiB contains a NUL is treated the same way, so a new desktop is protected against old hosts too.
    • Images and PDFs keep their preview path unchanged.

Why

  • Found while auditing large files on WSL hosts (checklist E7). The audit's other findings needed no change:
    • Every reply is capped at about 4 MiB.
    • The editor opens at most 50 MiB, refused up front from files.stat.
    • Diffs are capped at 10 MiB per side and must fit the 4 MiB reply.
    • Terminal output uses its own socket, and with WSL hosts its own wsl.exe relay, so a large read can't stall terminals.
  • Why reuse binary_file: every client, including mobile and older desktops, already handles it. A new result field would read as empty editable text to an older client, and saving that would wipe the file.
  • Why not gated behind the WSL flag: the read path is shared by every remote host, and the old behaviour is wrong everywhere.

Linked Issue

N/A (internal).

Visual Proof

N/A: an unlisted binary now shows the existing "binary file" view instead of garbled text; there is no new UI.

Testing

  • file-reads-binary-sniff.test.ts (host, real files): an unlisted .so is refused, a 2 MB file with an early NUL is refused from its first bytes, and text still reads.
  • runtime-file-client.test.ts:
    • a host's binary_file for a non-previewable file returns binary with one call;
    • an older host's text containing a NUL returns binary, with no files.readChunk and no files.readPreview.
  • pnpm tc, check:code-quality:changed, and the flaky-test, test-runner and max-lines checks pass. The renderer runtime and host file suites (332 files) pass locally. The full lint and test suites run in CI.

Review

Self-reviewed.

Agent skill upstream boundary

  • Not applicable.

Notes

  • Compatibility: no wire change. A new host only answers binary_file in more cases, which older clients already handle. A new desktop also protects itself against old hosts.
  • Mobile: already handles binary_file.
  • SSH: fixed the same way, since SSH hosts run this host code.

… to find out

A host decided files.read binaries by extension only. A binary with an extension it did not list
(.so, .o, .wasm, .class, ...) came back as text: under 512 KiB the editor opened it as text, where
a save writes the mangled text back; up to 50 MiB the desktop paged the whole file in before its
NUL check called it binary. Applies to WSL and SSH hosts and paired servers alike.

- The host checks the prefix it already reads for a NUL byte (git's own heuristic) and answers the
  existing `binary_file` refusal, which every client handles.
- The desktop shows any binary that has nothing to preview (not an image or PDF) as binary at once,
  without fetching a preview or paging (readRemoteBinaryFile); and treats text from an older host
  whose first 8 KiB holds a NUL the same way.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 09f55ea2-96d9-43ef-a00f-ab9809304416
Commits

Reviewing files that changed from the base of the PR and between c017ef9 and ea3662f.

Files selected for processing: 5
  • src/main/runtime/files/file-reads-binary-sniff.test.ts
  • src/main/runtime/files/file-reads.ts
  • src/renderer/src/runtime/runtime-file-client.test.ts
  • src/renderer/src/runtime/runtime-file-read-client.ts
  • src/renderer/src/runtime/runtime-paged-file-read.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit ca2cf3e into main Oct 28, 2026
48 checks passed
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.

1 participant