Skip to content

osfs: Fix infinite recursion in abs with empty baseDir#212

Closed
andrew wants to merge 2 commits into
go-git:mainfrom
andrew:fix-abs-empty-basedir
Closed

osfs: Fix infinite recursion in abs with empty baseDir#212
andrew wants to merge 2 commits into
go-git:mainfrom
andrew:fix-abs-empty-basedir

Conversation

@andrew
Copy link
Copy Markdown

@andrew andrew commented May 9, 2026

When baseDir is empty and deduplicatePath is enabled, the dedup prefix collapses to "" so strings.HasPrefix(path, "/") matches any absolute path and abs recurses on the same input until the stack overflows.

Skip deduplication when there is no baseDir to deduplicate. absNoFollow already has the equivalent guard.

Fixes #209

Copilot AI review requested due to automatic review settings May 9, 2026 11:53
Copy link
Copy Markdown

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

Fixes a stack overflow in BoundOS.abs when baseDir is empty and path deduplication is enabled (issue #209), by skipping the deduplication logic when there is no base directory to deduplicate.

Changes:

  • Guard BoundOS.abs deduplication to only run when baseDir != "", preventing infinite recursion.
  • Add a regression test covering abs behavior when baseDir is empty.

Reviewed changes

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

File Description
osfs/os_bound.go Adds a baseDir != "" guard around deduplication logic to prevent recursion.
osfs/os_bound_test.go Adds TestAbsEmptyBaseDir to ensure abs works when baseDir is empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread osfs/os_bound_test.go Outdated
got, err := fs.abs(filepath.FromSlash("/tmp"))
require.NoError(t, err)

want, err := securejoin.SecureJoin("", filepath.FromSlash("/tmp"))
andrew added 2 commits May 9, 2026 13:19
When baseDir is empty and deduplicatePath is enabled, the dedup prefix
collapses to "" so any absolute path matches and abs recurses on the
same input until the stack overflows. Skip deduplication when there is
no baseDir to deduplicate.

Fixes go-git#209

Signed-off-by: Andrew Nesbitt <andrewnez@gmail.com>
Signed-off-by: Andrew Nesbitt <andrewnez@gmail.com>
@andrew andrew force-pushed the fix-abs-empty-basedir branch from 7856e45 to 9aed6d0 Compare May 9, 2026 12:19
@pjbgf
Copy link
Copy Markdown
Member

pjbgf commented May 11, 2026

@andrew thanks for submitting this.

I believe this has been superseded by #211, and deduplicatePath no longer exists in the code base.

@andrew
Copy link
Copy Markdown
Author

andrew commented May 11, 2026

Yep, closing, thanks!

@andrew andrew closed this May 11, 2026
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.

BoundOS.abs recurses forever when baseDir is empty

3 participants