osfs: Fix infinite recursion in abs with empty baseDir#212
Closed
andrew wants to merge 2 commits into
Closed
Conversation
There was a problem hiding this comment.
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.absdeduplication to only run whenbaseDir != "", preventing infinite recursion. - Add a regression test covering
absbehavior whenbaseDiris 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.
| got, err := fs.abs(filepath.FromSlash("/tmp")) | ||
| require.NoError(t, err) | ||
|
|
||
| want, err := securejoin.SecureJoin("", filepath.FromSlash("/tmp")) |
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>
7856e45 to
9aed6d0
Compare
Member
Author
|
Yep, closing, thanks! |
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.
When
baseDiris empty anddeduplicatePathis enabled, the dedup prefix collapses to""sostrings.HasPrefix(path, "/")matches any absolute path andabsrecurses on the same input until the stack overflows.Skip deduplication when there is no
baseDirto deduplicate.absNoFollowalready has the equivalent guard.Fixes #209