Repository navigation
fix(repos): refuse bad link text, file links ending in /, and FIFOs - #1327
Open
vchamarthi wants to merge 2 commits into
Open
vchamarthi wants to merge 2 commits into
vchamarthi wants to merge 2 commits into
Conversation
`GitTree._follow` decoded link text strictly, so a committed link with non-UTF-8 text ended `repo scan` and `repo inspect` in a traceback; it now raises `SourceArgumentError`, which the scan reports as not scanned. `resolve` accepted a link such as `nul.md -> real.md/`, which is ENOTDIR in a checkout; both trees now refuse it. `WorkTree` opened a FIFO, so `repo scan` and `repo budget` waited for a writer; it now refuses a non-regular file, and names it as such instead of "links to nothing". Fixes intel#1272 Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
6 open issues
Relying on substring matching instr(err)is brittle (message text changes, localization, or… · New The_readable()docstring states the path is opened only if it is a regular file, but the code… · New When the resolved target exists but is non-regular, the error message uses onlyrel(the resolved… · Newos.symlink()with abytestarget is not portable (notably on Windows it can raiseTypeError).… · New The changelog references#1327, but the PR description and related issues mentioned here are… · New The docstring example saysnul.md -> real.md/but the setup usesreal.yaml/. Updating the… · New
What changed in this PR
Fixes incorrect/hanging handling of certain guidance paths across repo scan, repo budget, and repo inspect, specifically non‑UTF‑8 symlink text, symlink targets ending with / that actually resolve to files, and FIFOs in worktrees.
Changes:
- Add directory-requirement tracking for symlink texts ending in
/and raise_NoSuchPath(ENOTDIR semantics) when they resolve to a file. - Refuse committed symlinks whose blob text is not UTF‑8 by raising
SourceArgumentError(avoidsUnicodeDecodeErrortracebacks). - Prevent hangs/misclassification by treating FIFOs/devices/sockets as “not a regular file” in
WorkTreeread/resolve paths and reporting this inrepo budget.
| File | Description |
|---|---|
| dokimi/tests/test_repo_source_links.py | Adds regression tests for trailing-slash symlinks, non‑UTF‑8 link blobs, and FIFO behavior in worktree + CLI commands |
| dokimi/dokimi/repos/source.py | Implements UTF‑8 refusal for Git symlink blobs and adds non-regular-file guarding for WorkTree reads/resolve |
| dokimi/dokimi/repos/links.py | Preserves trailing / semantics through link walking and enforces “must be directory” when required |
| dokimi/dokimi/repos/budget.py | Improves unreadable-reason reporting to surface “not a regular file” |
| dokimi/changelog.d/20261126_120000_source-link-text-and-fifo.md | Changelog entry describing the fixed behaviors |
Review effort: Lite
Comment on lines
426
to
431
| def _unreadable_reason(err: Exception) -> str: | ||
| if isinstance(err, UnicodeDecodeError): | ||
| return "non-UTF-8 or binary" | ||
| if "is not a regular file" in str(err): # a FIFO, socket or device (#1272) | ||
| return "not a regular file" | ||
| return "not found, broken link, or outside tree" # dangling symlink, loop, escape, source error |
Comment on lines
+195
to
+204
| def _readable(self, path: str) -> Path: | ||
| """The file ``path`` names, which is opened only if it is a regular file: opening a FIFO waits for a writer (#1272).""" | ||
| target = self._resolve(path) | ||
| try: | ||
| mode = os.stat(target).st_mode | ||
| except OSError: | ||
| return target # the open reports it | ||
| if not stat.S_ISREG(mode) and not stat.S_ISDIR(mode): | ||
| raise SourceArgumentError(f"{path} is not a regular file (#1272: opening a FIFO waits for a writer)") | ||
| return target |
| raise SourceArgumentError(f"{path} links to nothing: {target.relative_to(self.root).as_posix()}") | ||
| rel = target.relative_to(self.root).as_posix() | ||
| if target.exists(): # a FIFO, socket or device: present, but not a file to read (#1272) | ||
| raise SourceArgumentError(f"{rel} is not a regular file") |
Comment on lines
+308
to
+313
| root = tmp_path / "repo" | ||
| (root / ".github").mkdir(parents=True) | ||
| os.symlink(b"r\xe9al", os.fsencode(root / ".github" / "instructions")) | ||
| (root / "AGENTS.md").write_text("See [x](.github/instructions/a.instructions.md)\n", encoding="utf-8") | ||
| git = lambda *a: subprocess.run(["git", "-c", "user.name=n", "-c", "user.email=a@b", *a], cwd=root, # noqa: E731 | ||
| check=True, capture_output=True).stdout.decode().strip() |
| @@ -0,0 +1,3 @@ | |||
| ### Fixed | |||
|
|
|||
| - **`repo scan`, `repo budget` and `repo inspect` handle unreadable guidance links and FIFOs** — a committed link whose text is not UTF-8 is now reported as `guidance file not scanned` instead of ending in a `UnicodeDecodeError` traceback; a link whose target is a file followed by `/` (`nul.md -> real.md/`) is no longer counted as that file, as in a checkout; and a FIFO guidance file in a plain directory no longer blocks the command: it is reported as `not a regular file` rather than `links to nothing` (#1272, #PR_NUMBER). | |||
|
|
||
|
|
||
| def test_a_link_to_a_file_with_a_trailing_slash_names_no_file_in_both_trees(tmp_path): | ||
| """#1272: ``nul.md -> real.md/`` is ENOTDIR in a checkout, so neither tree resolves it.""" |
This branch has not been deployed
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
repo scan,repo budgetandrepo inspectmishandled three kinds of guidance path: a committed link whose text is not UTF-8 (traceback), a link ending in/that names a file (counted as that file), and a FIFO in a plain directory (the command waited forever, or the file was called a link). This fixes all six scenarios of #1272. Related: #1273 (samelinks to nothingmessage for a FIFO, nowis not a regular file) and #1271 (same FIFO listing andrepo inspectread).Changes
GitTree._followreads link text through a new_link_textand raisesSourceArgumentErrorwhen it is not UTF-8, soread_manyand the scan record it as skipped.links._walk_linksandGitTree._followremember that a link text ended in/and raise_NoSuchPathwhen what they reach is not a directory, soresolverefusesnul.md -> real.md/in a tree and at a revision.WorkTree.read_textandread_bytescheckS_ISREGbefore opening;WorkTree.resolvesaysis not a regular filefor an existing FIFO, socket or device instead oflinks to nothing.links.py_require_dir(cat nul.mdfails withNot a directoryfornul.md -> real.md/) andsource.pyWorkTree._readable(opening a FIFO waits for a writer); the second names the issue in its message.budget._unreadable_reasonreports anot a regular fileerror as such, sorepo budgetno longer says a present FIFO is missing or a broken link.links._insidekeeps the trailing/of a rooted link text (and of the last link it walks outside the root), so the directory requirement survives a link chain that leaves and re-enters the root.Risk
Small. Only paths that raised, hung or were miscounted change. A link text ending in
/that reaches a directory still resolves. A directory is still passed to the open as before, so its error is unchanged. The FIFO guard is inWorkTreeonly;GitTreeholds no FIFOs.Testing
New tests in
tests/test_repo_source_links.pycover the trailing slash (tree and revision, and a chain), non-UTF-8 link text for a file and for a directory link (including therepo scan <dir>@HEADexit code), theWorkTreereaders on a FIFO, andrepo scanandrepo budgeton a FIFOAGENTS.mdandCLAUDE.mdplus the instructions-file message. I ran that file withtests/test_growth_ratchet.py,tests/test_repo_l0.pyandtests/test_repo_budget.py(407 passed),ruff checkandmypyon the two source files.Open questions
None beyond the choices listed below.
SourceArgumentError(a refusal, exit 2 at worst), andread_manylists it as skipped over Treating the link as dangling and giving no error: The issue asks forguidance file not scanned: ...as for a link that escapes the repository. Is that the behaviour you want?/that reaches a file raises_NoSuchPath(aSourceError), as the..after a file case does over Converting it toSourceArgumentErrorwithlinks to nothing: Smallest change; the issue asks forSourceError. Is that the behaviour you want?WorkTree.read_text,read_bytesandresolve, so every reader gets it over Guarding each caller inbudget.pyandl0: One place; callers already catchSourceError. Is that the behaviour you want?Revert
A plain revert restores the old behaviour; nothing is stored.
Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)Review points edit lines of recent commits:
dokimi/dokimi/repos/links.py(7e52ceb fix(repo): a directory refuses a manifest link that leaves and re-ente). Each commit's own tests still pass; none of their assertions changes except those listed above for a scenario of the issue.Review points also changed
dokimi/dokimi/repos/budget.py; each change is for a point a test in this pull request reproduces.Checklist evidence
pytestpasses: 1 test file(s) changed; suite: 30405 passed; 1 failing test(s) fail on the base branch too: tests/test_repo_compare_interval.py::test_the_row_p_places_zero_where_large_deltas_round_p_at_zero_apart; 10 of 10 proof(s) fail before the changeruff,mypy, and schema checks pass: passed: ci.yml:static / ruff check, ci.yml:typecheck / mypy, ci.yml:static / schema-check, ci.yml:static / schema_compat vs the PR baseresolvetreats a link ending in/, a non-UTF-8 link, or a FIFO; the changelog fragment records the change.AGENTS.md: nothing left open; mutation of changed lines ranraise/exit and test names the doc, contract or issue it traces to: every new error path and test names a doc, contract or issue.github/.licenserc.yaml): no new source fileFixes #1272.