Skip to content

Windows: reject absolute and malformed paths in git tree writes#902

Open
pjbgf wants to merge 1 commit intomainfrom
pjbgf/empty-names
Open

Windows: reject absolute and malformed paths in git tree writes#902
pjbgf wants to merge 1 commit intomainfrom
pjbgf/empty-names

Conversation

@pjbgf
Copy link
Copy Markdown
Member

@pjbgf pjbgf commented Apr 9, 2026

On Windows, absolute paths (e.g., /C:/Users/...) could leak into ApplyTreeChanges, producing empty-named tree entries when split on "/". Add normalizeGitTreePath to validate tree paths are relative with no empty segments, and normalizeRepoRelativeTreePath to convert absolute paths to repo-relative before tree construction.

Fixes #886.


Note

Cursor Bugbot is generating a summary for commit d88f401. Configure here.

@pjbgf pjbgf requested a review from a team as a code owner April 9, 2026 15:21
Copilot AI review requested due to automatic review settings April 9, 2026 15:21
@pjbgf pjbgf changed the title fix: reject absolute and malformed paths in git tree writes Windows: reject absolute and malformed paths in git tree writes Apr 9, 2026
On Windows, absolute paths (e.g., /C:/Users/...) could leak into
ApplyTreeChanges, producing empty-named tree entries when split on "/".
Add normalizeGitTreePath to validate tree paths are relative with no
empty segments, and normalizeRepoRelativeTreePath to convert absolute
paths to repo-relative before tree construction.

Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens git-tree construction in the checkpoint/shadow-branch write path by ensuring only valid, repo-relative tree paths are used, preventing malformed entries (notably on Windows when absolute paths leak in).

Changes:

  • Added normalizeGitTreePath and integrated it into ApplyTreeChanges and BuildTreeFromEntries to reject absolute paths and invalid segments (empty, ., ..).
  • Added normalizeRepoRelativeTreePath to convert absolute in-repo filesystem paths back to repo-relative tree paths before building changes.
  • Added tests to ensure invalid paths are skipped and no empty-named tree entries are produced.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cmd/entire/cli/checkpoint/temporary.go Normalizes modified/deleted paths to repo-relative tree paths before applying tree surgery; normalizes metadata dir path passed into tree construction.
cmd/entire/cli/checkpoint/parse_tree.go Adds path normalization/validation and applies it inside ApplyTreeChanges; adds helpers to detect absolute paths and log skips.
cmd/entire/cli/checkpoint/parse_tree_test.go Adds coverage asserting invalid paths are skipped and tree entries never have empty names.
cmd/entire/cli/checkpoint/checkpoint_test.go Adds end-to-end-ish coverage for WriteTemporary path normalization (absolute in-repo -> relative) and invalid path skipping.

Comment on lines +368 to +374
func logInvalidGitTreePath(operation, path string, err error) {
slog.Warn("skipping invalid git tree path",
slog.String("operation", operation),
slog.String("path", path),
slog.String("error", err.Error()),
)
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logInvalidGitTreePath logs via slog.Warn, which bypasses the repo’s cli/logging package (and can end up on stderr rather than in .entire/logs/). Consider routing this through logging.Warn (e.g., with context.Background() or by threading a ctx into callers) to keep operational logs consistent with the rest of the codebase (see cmd/entire/cli/checkpoint/committed.go where warnings go through logging.Warn).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Shadow branches contain corrupted tree objects with empty filenames on Windows

3 participants