fix: tolerate NUL suffixes in symbolic ref files#2658
Merged
Conversation
Sebastian Thiel (Byron)
force-pushed
the
compliant-ref-parser
branch
from
June 20, 2026 11:00
b7b42af to
2e2c8a7
Compare
Loose symbolic ref files can contain bytes after a NUL terminator. Git treats those bytes as invisible when reading the referent, so a HEAD file like 'ref: refs/heads/main\0...' still resolves to refs/heads/main. gitoxide read the entire line until CR/LF before validating the symbolic target, which made the embedded NUL fail refname validation. Match Git by stopping symbolic target parsing at the first NUL byte, while leaving direct object ref parsing unchanged. Git baseline: local Git checkout 7760f83b59, refs/files-backend.c parse_loose_ref_contents() uses C-string semantics for symbolic referents; 'git symbolic-ref HEAD' returns refs/heads/main for a HEAD containing 'ref: refs/heads/main\0codex-hidden-head-metadata: status-clean-demo'. Co-authored-by: Sebastian Thiel <[email protected]>
Sebastian Thiel (Byron)
force-pushed
the
compliant-ref-parser
branch
from
June 20, 2026 12:32
2e2c8a7 to
5d702e3
Compare
Sebastian Thiel (Byron)
marked this pull request as ready for review
June 20, 2026 12:33
There was a problem hiding this comment.
Pull request overview
This PR updates loose symbolic reference parsing in gix-ref to match Git’s C-string behavior by ignoring any bytes after the first NUL (\0) in ref: … files (e.g., HEAD). This makes the implementation more permissive and avoids errors when symbolic ref files contain NUL-suffixed metadata.
Changes:
- Adjust symbolic ref parsing to stop the target path at the first NUL byte (in addition to CR/LF or end-of-input).
- Update rustdoc to document the new parsing behavior.
- Add a regression test asserting that NUL-suffixed symbolic targets parse and resolve to the prefix before the NUL.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| gix-ref/src/store/file/loose/reference/decode.rs | Extend symbolic ref path termination logic to include \0, aligning parsing with Git behavior. |
| gix-ref/tests/refs/file/reference.rs | Add a test ensuring NUL-suffixed symbolic ref contents parse as symbolic and use only the prefix before the NUL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sebastian Thiel (Byron)
enabled auto-merge
June 20, 2026 12:35
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.
Tasks
This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.
Everything below this line was generated by Codex GPT-5.
Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Summary
Tolerate NUL suffixes in loose symbolic ref files by parsing the symbolic target only up to the first NUL byte, matching Git's C-string behavior for symbolic referents.
Reported issue
Git baseline
Local Git checkout
7760f83b59showsparse_loose_ref_contents()inrefs/files-backend.cstores symbolic referents through C-string semantics. A command-level check with aHEADfile containingref: refs/heads/main\0codex-hidden-head-metadata: status-clean-demoreturnedrefs/heads/mainfromgit symbolic-ref HEAD.Validation
cargo test -p gix-ref --test refs file::reference::parse::valid::symbolic_ignores_nul_suffix_like_git -- --exactcargo test -p gix-ref --test refs file::reference::parse --cargo clippy -p gix-ref --test refs -- -D warningscargo test -p gix-ref --test refscodex review --commit 2e2c8a7f52f648369c054b6d060f5cde24f51a18