osfs: BoundOS.Stat fails when the base dir is a symlink to outside its parent
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 20/100
Direzione di ricerca
The report points to BoundOS's baseInfo behavior and says the regression began with commit 50c9641; start by reading that change and the related Stat implementation. Reproduce with a symlinked base directory as shown, then run the regression test mentioned by the linked pull request. Done means Stat on the base directory follows the symlink and the reproduction succeeds.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When the base dir of a BoundOS is a symlink whose target is outside the symlink's parent directory, Stat on the base dir itself ("", "." or "/") fails with ErrPathEscapesParent:
statat repo: path escapes from parent
Other calls on the same filesystem follow the symlink, because they open the base dir with os.OpenRoot: Stat(".git") and Lstat("/") succeed. Only baseInfo differs. Since 50c9641 it opens an os.Root on the parent and stats the base name inside it, so following the symlink counts as an escape.
This surfaces in go-git v6: PlainOpenWithOptions stats the base dir first, so a repository can't be opened through a symlinked working directory, while git works from the same path. We hit it in the Okteto CLI, where repository detection fails when users run it from a symlinked checkout.
Reproduction
mkdir -p /tmp/repro/real/repo /tmp/repro/work
git -C /tmp/repro/real/repo init
ln -s ../real/repo /tmp/repro/work/repo
go run . /tmp/repro/work/repo
package main
import (
"fmt"
"os"
"github.com/go-git/go-billy/v6/osfs"
"github.com/go-git/go-git/v6"
)
func main() {
path := os.Args[1]
fs := osfs.New(path, osfs.WithBoundOS())
_, err := fs.Stat("/")
fmt.Println("billy Stat(\"/\"):", err)
_, err = fs.Stat(".git")
fmt.Println("billy Stat(\".git\"):", err)
_, err = git.PlainOpenWithOptions(path, &git.PlainOpenOptions{DetectDotGit: true})
fmt.Println("go-git PlainOpenWithOptions:", err)
}
Output with go-billy v6.0.0-beta.1 and go-git v6.0.0-beta.1:
billy Stat("/"): statat repo: path escapes from parent
billy Stat(".git"): <nil>
go-git PlainOpenWithOptions: statat repo: path escapes from parent
git -C /tmp/repro/work/repo rev-parse --show-toplevel succeeds.
Versions
- go-billy
v6.0.0-alpha.2,v6.0.0-beta.1andmain(d67c9b5) - go-git
v6.0.0-alpha.5andv6.0.0-beta.1; go-git v5 is not affected - Go 1.27.3, macOS arm64
Expected behaviour
Stat on the base dir follows the symlink, like the other calls on the same filesystem and like git.
I have a fix with a regression test and will open a PR.
- Lingua principale
- Go
- Stelle
- 433
- Fork
- 83
- Merge medio
- 1g 11h
- PR unite (30g)
- 4
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di go-git/go-billy
-
osfs: RootOS.ReadDir does not sort entries by filenameForse già presa @erka l’ha presa 192 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
memfs: independent O_APPEND handles silently overwrite earlier writesForse già presa @harbinresearcher l’ha presa 41 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
-
Building on Plan 9 stopped working, which breaks github.com/u-root/cpuForse già presa @rminnich l’ha presa 159 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Built-in support for mmapApertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Should we add a new capability of Executable?Forse di nuovo libera @kayoch1n l’ha presa 368 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement
Tutte le issue di go-git/go-billy
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
alibaba/MongoShake#1077 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
mattermost/mattermost-plugin-jira#1397 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
I maintainer di solito rispondono entro 3 giorni
-
Add Free CS Systems Workshops, Starter Scaffolds & Zero-Dependency Verification CLI to CS SeriesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100