Skip to content

diff: Reject invalid hunk prefixes before slicing UTF-8 - #3473

Draft
huacnlee wants to merge 1 commit into
mainfrom
fix/diff-unicode-hunk-prefix-20261013
Draft

huacnlee wants to merge 1 commit into
mainfrom
fix/diff-unicode-hunk-prefix-20261013

Conversation

@huacnlee

@huacnlee huacnlee commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Description

A malformed hunk source line beginning with a multibyte UTF-8 character panics before the parser can return DiffParseError. parse_hunk sliced &content[1..] before checking whether the first byte was a valid hunk prefix.

Validate the ASCII prefix first, then remove it only for space, + and -. Invalid prefixes retain the existing error message and one-based patch line. Empty context lines stripped by editors/mail transports remain supported.

Minimal input: --- a/a\n+++ b/a\n@@ -1 +1 @@\néinvalid\n.

Regression coverage

  • Invalid 2-, 3- and 4-byte Unicode prefixes (é, 中, 😀) and an invalid ASCII prefix return the line-4 parse error.
  • Valid context, deleted and added lines preserve their Unicode source.
  • Existing empty-context and malformed-hunk tests remain unchanged.

Public API

None. No Base-layer, dependency or UI changes.

Validation

  • Independent source review completed.
  • Patch application and whitespace checks passed against main 369f7a8f5a6602da980f008cf726467588ad517f.
  • Local Rust tests, rustfmt and clippy were not run: the saved coding environment failed to start, and the available workspace has no Rust toolchain.
  • CI run 38328586529 passed all 15 jobs for head 2846b8d612f96ebd5dda65c1348bf104200d5149, including standard macOS/Linux/Windows tests, GPUI Fast, lint and Shell checks.
  • The Linux test log records both new Unicode regression tests passing; the Component unit suite passed 708 tests.
  • The PR remains a draft for maintainer review. Focused rerun: cargo test -p gpui-component --lib diff::parser_tests.

AI-assisted: prepared and independently source-reviewed with OpenAI Codex.

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