[Bug]: `ImageStore.load` fails with "item with the same name already exists" when two index descriptors reach a blob already in the content store

Aperta
#1,017 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, swift

Direzione di ricerca

Start in ImageStore.load(from:) in ImageStore+OCILayout.swift (lines 74-109), which runs one ImportOperation per index.json descriptor into a shared ingest directory. The copy that fails is in ImportOperation.fetch in ImageStore+Import.swift (around lines 185-196). Reproduce with an archive that has two descriptors sharing one digest, then check that the load succeeds and both names are present.

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

Descrizione

I have done the following
  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Not built from main, but ImageStore+OCILayout.swift and ImageStore+Import.swift on main (706cb51) are unchanged since 0.54.0.

Steps to reproduce

With container 1.7.1 (containerization 0.54.0):

container image pull alpine:3.22
container image tag alpine:3.22 repro:a
container image tag alpine:3.22 repro:b
container image save repro:a repro:b -o repro.tar
container image load -i repro.tar

repro.tar's index.json has two descriptors with the same digest, one per name:

sha256:49340b346798… docker.io/library/repro:a
sha256:49340b346798… docker.io/library/repro:b
Current behavior
Error: Error Domain=NSCocoaErrorDomain Code=516 "“49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f” couldn’t be copied to “180743FD-86FE-4424-B329-87ED09331F2B” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=~/Library/Application Support/com.apple.container/content/blobs/sha256/49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f, NSUserStringVariant=(
    Copy
), NSDestinationFilePath=~/Library/Application Support/com.apple.container/content/ingest/180743FD-86FE-4424-B329-87ED09331F2B/49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f, NSFilePath=~/Library/Application Support/com.apple.container/content/blobs/sha256/49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f, NSURL=file:///~/Library/Application%20Support/com.apple.container/content/blobs/sha256/49340b346798875b5592e5d420241f2f9cfba5f47e62ebb1446a1b34734e898f, NSUnderlyingError=0x75190bdec0 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}

container image save repro:a -o single.tar followed by container image load -i single.tar (one descriptor) succeeds.

Expected behavior

Both names load, as docker load does for the same archive.

Cause

ImageStore.load(from:) (ImageStore+OCILayout.swift, lines 74-109) opens one ingest session and runs an ImportOperation for every descriptor of index.json into the same ingest directory. ImportOperation.fetch (ImageStore+Import.swift, around lines 185-196) copies a blob the content store already has into that directory with FileManager.copyItem. When an earlier descriptor in the same load has already copied that blob, the copy fails with EEXIST.

So any multi-descriptor index whose descriptors share a stored blob fails, including:

  • container image save of two tags of one image, as above;
  • docker save of several tags from Docker 25+, which writes one descriptor per tag (Moby image/tarexport/save.go);
  • BuildKit's OCI/Docker exporter with several names (exporter/oci/export.go → containerd archive.WithManifest(desc, names...), one descriptor per name);
  • several images that share a base layer that is already stored.

A possible fix is to skip the copy when the destination already exists in the ingest directory, since the content is identical by digest.

Environment
  • OS: macOS 27.2.1 (Apple Silicon)
  • Xcode: 27.2
  • Container: 1.7.1 (build: release, commit: a15b460), containerization 0.54.0
Code of Conduct
  • I agree to follow this project's Code of Conduct
Lingua principale
Swift
Stelle
9k
Fork
412
Merge medio
3g 10h
PR unite (30g)
12

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 apple/containerization

Tutte le issue di apple/containerization

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.