`gh` crashes with a stack overflow when an alias expands to itself

Ouverte Adaptée aux débutants
#14,986 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #14995 par @ump45nose — fermée sans fusion
  • #15107 par @ArianPashae — fermée sans fusion

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
76/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
go
Domaine
cli

Piste de recherche

Commencez dans pkg/cmd/root/alias.go, où la trace de pile montre que l’expansion de l’alias se réappelle elle-même, et lisez les tests d’alias à proximité pour voir comment les alias sont testés. Reproduisez l’échec avec un alias autoréférentiel, puis ajoutez des tests couvrant le comportement d’erreur attendu et vérifiez que l’exécution de l’alias se termine sans plantage.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug gh-alias priority-3
Describe the bug

gh crashes with a stack overflow when an alias expands to itself.

An alias whose expansion resolves back to the same alias is accepted without complaint, and running it re-enters the alias forever until the Go runtime aborts the process.

Affected version
$ gh version
gh version 2.103.3-71-g736c68f67 (2026-11-07)
https://github.com/cli/cli/releases/latest

This is a build of trunk.

Steps to reproduce the behavior
  1. Create an alias that expands to itself:

    gh alias set 'issue mine' 'issue mine'
    

    This is accepted and exits 0.

  2. Run the alias:

    gh issue mine
    
  3. See error

The same happens when the alias arrives through gh alias import, which is how a shared alias file would carry it:

$ cat aliases.yml
pr mine: pr mine

$ gh alias import aliases.yml
$ gh pr mine
Expected vs actual behavior

Expected: gh should either refuse to create an alias that expands to itself, or report an error when the alias is run.

Actual: gh recurses until the runtime aborts the process with fatal error: stack overflow, after about 30 seconds and roughly 1 GB of goroutine stack.

Logs
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x184c88b003a8 stack=[0x184c88b00000, 0x184ca8b00000]
fatal error: stack overflow

runtime stack:
	runtime/panic.go:1243 +0x48
	runtime/stack.go:1207 +0x5dd
	runtime/asm_amd64.s:650 +0x7b

goroutine 1 gp=0x184c62f4a1e0 m=23 mp=0x184c74808008 [running]:
regexp/syntax.(*compiler).rune(...)
	regexp/syntax/compile.go:272 +0x2d3
...
regexp.MustCompile({0x14effea, 0x4})
	regexp/regexp.go:310 +0x2c
github.com/cli/cli/v2/pkg/cmd/root.expandAlias({0x184c6349faa0?, 0x184c633e2ab0?}, {0x2b1f980?, 0x0, 0x14f3f6a?})
	github.com/cli/cli/v2/pkg/cmd/root/alias.go:91 +0x28a
github.com/cli/cli/v2/pkg/cmd/root.NewCmdAlias.func1(0x184c6372d808, {0x2b1f980?, 0x4?, 0x14efff2?})
	github.com/cli/cli/v2/pkg/cmd/root/alias.go:58 +0x35
github.com/spf13/cobra.(*Command).execute(0x184c6372d808, {0x2b1f980, 0x0, 0x0})
	github.com/spf13/[email protected]/command.go:1015 +0xb3c
github.com/spf13/cobra.(*Command).ExecuteC(0x184c6372d808)
	github.com/spf13/[email protected]/command.go:1148 +0x450
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:1071
github.com/cli/cli/v2/pkg/cmd/root.NewCmdAlias.func1(...)
	github.com/cli/cli/v2/pkg/cmd/root/alias.go:64 +0xb2
github.com/spf13/cobra.(*Command).execute(...)
	github.com/spf13/[email protected]/command.go:1015 +0xb3c
github.com/spf13/cobra.(*Command).ExecuteC(...)
	github.com/spf13/[email protected]/command.go:1148 +0x450
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:1071
github.com/cli/cli/v2/pkg/cmd/root.NewCmdAlias.func1(...)
	github.com/cli/cli/v2/pkg/cmd/root/alias.go:64 +0xb2
... and the same two frames repeat until the stack limit is hit
exit status 2
Langage dominant
Go
Étoiles
47.4k
Forks
9.5k
Merge moyen
18 h 34 min
PR mergées (30 j)
70

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de cli/cli

Toutes les issues de cli/cli

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.