osfs: BoundOS.Stat fails when the base dir is a symlink to outside its parent

Aperta
#254 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@jLopezbarb ci sta già lavorando.

Dal 11/11/2026.

  • #255 di @jLopezbarb — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

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.1 and main (d67c9b5)
  • go-git v6.0.0-alpha.5 and v6.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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di go-git/go-billy

Tutte le issue di go-git/go-billy

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.