fix: preserve per-occurrence layer identity in mutate.Image.Layers()#2299
Merged
Subserial merged 2 commits intoMay 15, 2026
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2299 +/- ##
=======================================
Coverage 56.89% 56.89%
=======================================
Files 165 165
Lines 11334 11331 -3
=======================================
- Hits 6448 6447 -1
+ Misses 4121 4120 -1
+ Partials 765 764 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Subserial
reviewed
May 15, 2026
Subserial
left a comment
Contributor
There was a problem hiding this comment.
LGTM, I can merge this once the language checks pass.
When a base image and an appended layer share a diff ID but have different blob digests (e.g. same uncompressed tar, different compression), mutate.Image.Layers() previously returned the appended layer twice instead of [base, appended]. The manifest still listed both digests correctly, but downstream code that walks Layers() to upload blobs would upload the appended layer twice and never push the base's blob, so the PUT manifest would fail with MANIFEST_BLOB_UNKNOWN. Root cause: Layers() walked the rootfs diff IDs and resolved each via LayerByDiffID, which can't disambiguate two layers with the same diff ID — the addendum overwrites the base entry in diffIDMap. The manifest layer descriptors are already unambiguous (one entry per occurrence, each with its own digest), so walk those instead and resolve via LayerByDigest. Same length and order, but per-occurrence identity is preserved. Fixes google#2034
23fe3de to
88af782
Compare
Subserial
approved these changes
May 15, 2026
Subserial
pushed a commit
to Subserial/go-containerregistry
that referenced
this pull request
May 15, 2026
When a base image and an appended layer share a diff ID but have different blob digests (e.g. same uncompressed tar, different compression), mutate.Image.Layers() previously returned the appended layer twice instead of [base, appended]. The manifest still listed both digests correctly, but downstream code that walks Layers() to upload blobs would upload the appended layer twice and never push the base's blob, so the PUT manifest would fail with MANIFEST_BLOB_UNKNOWN. Root cause: Layers() walked the rootfs diff IDs and resolved each via LayerByDiffID, which can't disambiguate two layers with the same diff ID — the addendum overwrites the base entry in diffIDMap. The manifest layer descriptors are already unambiguous (one entry per occurrence, each with its own digest), so walk those instead and resolve via LayerByDigest. Same length and order, but per-occurrence identity is preserved. Fixes google#2034
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2034.
When a base image and an appended layer share a diff ID but have different blob digests — same uncompressed content, different compression —
mutate.Image.Layers()was returning the appended layer twice instead of[base, appended]. The manifest itself still listed both digests correctly, but downstream code that walksLayers()to upload blobs would push the appended layer twice and never upload the base's blob, so the final manifest PUT failed withMANIFEST_BLOB_UNKNOWN. The reporter hit this through kaniko; another commenter ran into the same thing viacrane appendwith RPM-extracted tarballs.The root cause is in
pkg/v1/mutate/image.go.Layers()walked the rootfs diff IDs and resolved each one viaLayerByDiffID, which has no way to disambiguate two layers that share a diff ID — the addendum overwrites the base entry indiffIDMapduringcompute(), so both diff-ID lookups return the same (appended) layer.The manifest layer descriptors are already unambiguous: one entry per occurrence, each with its own digest. Walking those and resolving via
LayerByDigestkeeps the same length and order but preserves per-occurrence identity.LayerByDigestnaturally handles the case becausedigestMapis keyed on (unique) digests, and base-image digests fall through toi.base.LayerByDigest.Added
TestAppendLayers_DuplicateDiffIDcovering it — uses a thin wrapper that reports the inner layer's DiffID with its own Digest/Size/Compressed, which is how the bug shows up in practice. Confirmed the test fails onmain(returns the wrong layer at index 0) and passes with this change. Fullpkg/v1/mutatesuite passes with-race.