Skip to content

tarball: bounds-check layer index in uncompressed LayerByDiffID - #2370

Merged
Subserial merged 2 commits into
google:mainfrom
arpitjain099:fix/tarball-uncompressed-diffids-bounds
Jul 25, 2026
Merged

Subserial merged 2 commits into
google:mainfrom
arpitjain099:fix/tarball-uncompressed-diffids-bounds

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

uncompressedImage.LayerByDiffID ranges over the config's rootfs.diff_ids and then uses that index against imgDescriptor.Layers, which comes from manifest.json. Those two are parsed separately and never compared, so a config declaring more diff_ids than manifest.json lists layers indexes past the end.

The compressed side got this guard in #2304, the uncompressed one didn't. Same mismatch, other direction.

It's reachable from the public API. partial.uncompressedImageExtender.Layers() calls LayerByDiffID for every config diff_id, so tarball.ImageFromPath(...).Layers() on a crafted docker save tarball panics instead of returning an error.

Before the fix, on a two-file tarball with "Layers":[] in manifest.json and one diff_id in the config:

panic: runtime error: index out of range [0] with length 0
    tarball.(*uncompressedImage).LayerByDiffID
        pkg/v1/tarball/image.go:338
    partial.(*uncompressedImageExtender).LayerByDiffID
        pkg/v1/partial/uncompressed.go:209
    partial.(*uncompressedImageExtender).Layers
        pkg/v1/partial/uncompressed.go:198

The guard mirrors #2304's and returns an error. New test TestLayerByDiffIDMoreDiffIDsThanLayers panics without the change and passes with it. go test ./pkg/v1/tarball/... ./pkg/v1/partial/... -count=1 and go vet ./pkg/v1/tarball/... are green.

arpitjain099 and others added 2 commits July 15, 2026 20:41
The compressed side got this guard in #2304. LayerByDiffID walks the
config's rootfs.diff_ids and indexes imgDescriptor.Layers with the same
index, so a config declaring more diff_ids than manifest.json lists
layers panics with an index out of range instead of returning an error.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.14%. Comparing base (b3a7149) to head (fa62f33).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2370   +/-   ##
=======================================
  Coverage   57.13%   57.14%           
=======================================
  Files         166      166           
  Lines       11473    11475    +2     
=======================================
+ Hits         6555     6557    +2     
  Misses       4141     4141           
  Partials      777      777           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Subserial
Subserial merged commit afc8f33 into google:main Jul 25, 2026
22 checks passed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
crane 0.21.8

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>The artifacts attached to this release are missing SLSA provenance, see #2390.

## What's Changed
* build(deps): bump the go-deps group across 1 directory with 3 updates by @dependabot[bot] in google/go-containerregistry#2353
* build(deps): bump golang.org/x/crypto from 0.45.0 to 0.52.0 in /cmd/krane by @dependabot[bot] in google/go-containerregistry#2367
* build(deps): bump golang.org/x/crypto from 0.50.0 to 0.52.0 in /pkg/authn/k8schain by @dependabot[bot] in google/go-containerregistry#2368
* build(deps): bump golang.org/x/net from 0.49.0 to 0.55.0 in /pkg/authn/kubernetes by @dependabot[bot] in google/go-containerregistry#2363
* build(deps): bump the go-deps group across 3 directories with 7 updates by @dependabot[bot] in google/go-containerregistry#2377
* build(deps): bump the actions group across 1 directory with 5 updates by @dependabot[bot] in google/go-containerregistry#2375
* Reject unsafe Windows archive paths in Extract by @Haihan-Jiang in google/go-containerregistry#2330
* feat(goreleaser): add loong64 build support for crane/gcrane/krane by @xuxiaowei-com-cn in google/go-containerregistry#2358
* Document tag and digest reference semantics by @Haihan-Jiang in google/go-containerregistry#2325
* remote: release pull limiter slot when body is read to EOF by @knQzx in google/go-containerregistry#2373
* tarball: bounds-check layer index in uncompressed LayerByDiffID by @arpitjain099 in google/go-containerregistry#2370
* authn: read Podman auth from XDG config by @vigneshakaviki in google/go-containerregistry#2379
* transport: per-host bearer token exchange on cross-host redirect by @amitzig in google/go-containerregistry#2360
* mutate: bounds-check layer index when building rebase addendums by @arpitjain099 in google/go-containerregistry#2371
* fix(daemon): copy ExposedPorts from source config in computeImageConfig by @x64vps in google/go-containerregistry#2356
* feat(remote): add WithReferrersTagFallback option by @kevinmdavis in google/go-containerregistry#2366
* mutate: apply opaque-directory whiteouts (.wh..wh..opq) in Extract by @sadmanf in google/go-containerregistry#2372
* tarball: use correct file extension for zstd/uncompressed by @milas in google/go-containerregistry#2382
* build(deps): bump github.com/moby/moby/client from 0.5.0 to 0.5.1 in the go-deps group across 1 directory by @dependabot[bot] in google/go-containerregistry#2380
* actions: update actions to be pinned by hash by @Subserial in google/go-containerregistry#2384
* Bump go version to 1.26.5 by @Subserial in google/go-containerregistry#2388

## New Contributors
* @xuxiaowei-com-cn made their first contribution in google/go-containerregistry#2358
* @knQzx made their first contribution in google/go-containerregistry#2373
* @arpitjain099 made their first contribution in google/go-containerregistry#2370
* @vigneshakaviki made their first contribution in google/go-containerregistry#2379
* @amitzig made their first contribution in google/go-containerregistry#2360
* @x64vps made their first contribution in google/go-containerregistry#2356
* @kevinmdavis made their first contribution in google/go-containerregistry#2366
* @sadmanf made their first contribution in google/go-containerregistry#2372

**Full Changelog**: https://github.com/google/go-containerregistry/compare/v0.21.7...v0.21.8</pre>
  <p>View the full release notes at <a href="https://github.com/google/go-containerregistry/releases/tag/v0.21.8">https://github.com/google/go-containerregistry/releases/tag/v0.21.8</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!15552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants