Conversation
Contributor
Collaborator
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
Fix false binary classification when the 1,000-byte content sample splits a valid multibyte UTF-8 sequence.
ShellFileOperationscurrently sendshead -c 1000output through environment APIs that decode stdout witherrors="replace". A valid character beginning before byte 1,000 and ending after it therefore arrives as U+FFFD and is classified as binary.This change:
read_file()andread_file_raw()through the byte-safe sampler;patch_replace()is intentionally unchanged. Prefix classification does not prove an entire editable file is valid UTF-8, and the existing display-read helper performs lossy terminal-fence cleanup; edit-path hardening requires a separate lossless full-file snapshot design.The size probe, bounded sample, and final display read remain separate opens. Exact-length validation fails closed on many growth/shrink races, but it cannot detect same-size replacement or mutation after sampling. This PR fixes the byte-boundary classification defect; it does not claim stable-snapshot or full-file edit validation.
Relationship to existing PRs
Several open PRs address the same symptom, but this implementation differs at the safety boundary:
>30%low-control threshold.The regression matrix covers every split position for valid 2-, 3-, and 4-byte UTF-8 characters, malformed continuations at those positions, literal U+FFFD, true-EOF incompleteness, and invalid bytes beginning immediately after the logical boundary.
Reproduction
A valid 4,109-byte UTF-8 file with
E2at byte 1,000 and80 9Dimmediately after it:main:is_binary=Truewith “Binary file” error;is_binary=False, no error, and the closing quote is preserved.Verification
The exact
od -An -v -tx1 -Nform was also exercised with GNU coreutils and BusyBox. CI will provide the repository-wide test result.