Repository navigation
fix(files): never open a remote binary as text, and never page one in to find out - #34877
Merged
Merged
Conversation
… 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.
Contributor
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
5 tasks done
8 of 9 tasks
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.
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,.classand 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
files.readchecked only the extension list (isMobileBinaryPath).{ content, truncated: false }, and the editor opened it as editable text.readLocalMobileFileinsrc/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 existingbinary_filerefusal.readRuntimeFileContent,readRemoteBinaryFile):binary_filerefusal for a file with nothing to preview (not an image or PDF) shows as binary at once, with no preview fetch and no paging.Why
files.stat.wsl.exerelay, so a large read can't stall terminals.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.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.sois refused, a 2 MB file with an early NUL is refused from its first bytes, and text still reads.runtime-file-client.test.ts:binary_filefor a non-previewable file returns binary with one call;files.readChunkand nofiles.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
Notes
binary_filein more cases, which older clients already handle. A new desktop also protects itself against old hosts.binary_file.