fix: avoid infinite recursion while searching for path#585
Closed
yajo wants to merge 1 commit intonix-community:masterfrom
Closed
fix: avoid infinite recursion while searching for path#585yajo wants to merge 1 commit intonix-community:masterfrom
yajo wants to merge 1 commit intonix-community:masterfrom
Conversation
In `findGitIgnores`, to find the parent path, we do `path + "/.."`. This means that, for each iteration, the path name grows: 1. `/nix/store/1234-example/a/b/` 2. `/nix/store/1234-example/a/b/..` 3. `/nix/store/1234-example/a/b/../..` 4. etc. Thus, checking if path is not equal to `/` will always return `true`. With this fix, it will instead check that the path exists. If the path goes higher than `/`, it will not exist, thus fixing the false positive. @moduon MT-83
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-debug-infinite-recursion/18470/4 |
Member
This observation isn't entirely correct as we are dealing with a nix-repl> ./.
/home/adisbladis/sauce/github.com/nix-community/poetry2nix
nix-repl> ./. + "/.."
/home/adisbladis/sauce/github.com/nix-community
nix-repl> ./. + "/../.."
/home/adisbladis/sauce/github.comWhich eventually ends up at nix-repl> ./. + "/../../../../../../../../"
/Hence, this fix introduces an infinite recursion when there is no gitignore available since So instead of your fix which is lib.optionals (builtins.pathExists path && ! isGitRoot) (findGitIgnores parent) ++ gitIgnores;We'll need to lib.optionals (builtins.pathExists path && builtins.toString path != "/" && ! isGitRoot) (findGitIgnores parent) ++ gitIgnores; |
adisbladis
added a commit
that referenced
this pull request
Apr 14, 2022
fix: avoid infinite recursion while searching for path #585
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.
In
findGitIgnores, to find the parent path, we dopath + "/..". This means that, for each iteration, the path name grows:/nix/store/1234-example/a/b//nix/store/1234-example/a/b/../nix/store/1234-example/a/b/../..Thus, checking if path is not equal to
/will always returntrue.With this fix, it will instead check that the path exists. If the path goes higher than
/, it will not exist, thus fixing the false positive.Fixes the failure exercised in https://gitlab.com/moduon/mrchef/-/merge_requests/1.
You can reproduce it with:
The next commit includes the fix and won't fail:
@moduon MT-83