Skip to content

Preserve the index media type when the index body omits it - #2235

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
arpitjain099:fix/index-update-media-type
Oct 14, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
arpitjain099:fix/index-update-media-type

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

oras manifest index update takes the new descriptor's media type from index.MediaType, which is read out of the index body. mediaType is optional in older OCI indexes, so a body can omit it while the resolved descriptor correctly says image index. fetchIndex does gate the input with descriptor.IsIndex(desc), but that checks the descriptor the registry or layout supplies, not the body. With index.MediaType empty, content.NewDescriptorFromBytes substitutes application/octet-stream, the tag gets rewritten to point at it, and the artifact stops being resolvable as an index.

I reproduced it on a hand-built OCI layout with no registry. The update reports success and exits 0, but the tag's descriptor goes from application/vnd.oci.image.index.v1+json to application/octet-stream, and a second index update on the same tag then fails with v1 is not an index.

The fix falls back to desc.MediaType in fetchIndex, which is already in scope and already validated. That also writes mediaType into the new body, which OCI image-spec 1.1 requires for an index, so body and descriptor end up agreeing. create.go hardcodes ocispec.MediaTypeImageIndex, and I deliberately did not copy that here: a Docker manifest list would be silently retyped, so this needs to be a fallback rather than a constant. The test covers that case.

Test_fetchIndex_mediaType has three rows. The mediaType-less one fails on main with fetchIndex() MediaType = "", want "application/vnd.oci.image.index.v1+json"; the other two, a body that carries its mediaType and a Docker manifest list, pass either way. go test ./cmd/... ./internal/... is green.

Which issue(s) this PR fixes:

None filed.

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

No E2E case exists for a mediaType-less index (grep mediaType test/e2e/suite/command/manifest_index.go is empty). Happy to add one if you want it covered there as well.

AI assistance was used on this change and is disclosed in the commit trailer.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.62%. Comparing base (227fc74) to head (43f4487).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2235      +/-   ##
==========================================
+ Coverage   56.23%   57.62%   +1.39%     
==========================================
  Files         139      139              
  Lines        7453     6074    -1379     
==========================================
- Hits         4191     3500     -691     
+ Misses       3043     2355     -688     
  Partials      219      219              

☔ 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.

@TerryHowe
TerryHowe merged commit bae5056 into oras-project:main Oct 14, 2026
10 checks passed
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.

2 participants