public/manifest: IterateSlices and IterateContents also match other packages and slices sharing the name as a prefix

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

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Read public/manifest/manifest.go and inspect how IterateSlices and IterateContents build their jsonwall queries. The issue includes a reproducer for each prefix collision; compare the returned names and paths with the expected exact matches. Done means both methods return only the requested package's slices or slice's contents, while an empty name still lists all entries, with tests passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

IterateSlices(pkgName, ...) and IterateContents(slice, ...) in public/manifest/manifest.go pass the name to jsonwall as a raw prefix with no boundary:

func (manifest *Manifest) IterateSlices(pkgName string, onMatch func(*Slice) error) (err error) {
	return iteratePrefix(manifest, &Slice{Kind: "slice", Name: pkgName}, onMatch)
}

func (manifest *Manifest) IterateContents(slice string, onMatch func(*Content) error) (err error) {
	return iteratePrefix(manifest, &Content{Kind: "content", Slice: slice}, onMatch)
}

So a package or slice whose name starts with another one is returned too:

  • IterateSlices("libc6", ...) also yields libc6-dev_headers.
  • IterateContents("libc6_libs", ...) also yields the contents of libc6_libs-extra.

Inside chisel these are only called with "", so the existing tests never pass a name. For a consumer of the public package (an SBOM generator or scanner asking for one package's slices), the parameter names suggest a per-package and per-slice lookup.

Reproduction

On main (0a817bd), a test in public/manifest:

const prefixManifest = `{"jsonwall":"1.0","schema":"1.0","count":6}
{"kind":"content","slice":"libc6_libs","path":"/lib/a"}
{"kind":"content","slice":"libc6_libs-extra","path":"/lib/b"}
{"kind":"package","name":"libc6","version":"v1","sha256":"h1","arch":"amd64"}
{"kind":"package","name":"libc6-dev","version":"v1","sha256":"h2","arch":"amd64"}
{"kind":"slice","name":"libc6-dev_headers"}
{"kind":"slice","name":"libc6_libs"}
`

func (s *S) TestIterateSlicesOnlyMatchesPackage(c *C) {
	mfest, err := manifest.Read(strings.NewReader(prefixManifest))
	c.Assert(err, IsNil)
	var names []string
	err = mfest.IterateSlices("libc6", func(sl *manifest.Slice) error {
		names = append(names, sl.Name)
		return nil
	})
	c.Assert(err, IsNil)
	c.Assert(names, DeepEquals, []string{"libc6_libs"})
}
obtained []string{"libc6-dev_headers", "libc6_libs"}
expected []string{"libc6_libs"}

The same test for IterateContents("libc6_libs") returns both /lib/a and /lib/b.

Possible fix
  • IterateSlices: when pkgName != "", iterate with the prefix pkgName + "_" (slice names are <pkg>_<slice>).
  • IterateContents: match the slice name exactly (jsonwall Iterate instead of IteratePrefix); an empty name still lists all contents.

Since this changes what the public API returns, I wanted to confirm the intended semantics before sending a PR. I have the change with tests ready and go test ./... passing, and I have signed the CLA.

Lingua principale
Go
Stelle
434
Fork
74
Merge medio
1g 30m
PR unite (30g)
1

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

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 canonical/chisel

Tutte le issue di canonical/chisel

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.