Bound the manifest layer index in ociLayoutPackage.GetLayer#2651
Open
arpitjain099 wants to merge 3 commits into
Open
Bound the manifest layer index in ociLayoutPackage.GetLayer#2651arpitjain099 wants to merge 3 commits into
arpitjain099 wants to merge 3 commits into
Conversation
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Member
|
Hi @arpitjain099 , thanks for reporting! Could you add a test case for this scenario? Also, could you create an issue to keep track of the fix? |
…heck Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Author
|
Thanks @jjbustamante. I added a test in |
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.
Summary
ociLayoutPackage.GetLayerfinds a layer's position by matching the requested diffID against the image config'srootfs.diff_ids, then uses that index into the manifest'slayersarray. The configdiff_idsand the manifestlayersare two separate arrays in the buildpackage, and nothing enforces they are the same length. A buildpackage whose config declares more diff_ids than the manifest lists layers makesindex >= len(o.manifest.Layers), so it panics with an index-out-of-range.Both arrays, plus the diffID (which comes from the
io.buildpacks.buildpack.layerslabel), are part of the OCI-layout blob, so this is reachable frompack buildpack package,pack builder create, andpack build --buildpack <path>on a crafted.cnb. This adds a bounds check that returns a clear error instead of panicking, in line with how the imgutil-backed image path resolves layers by diffID directly. A regression test was added inpkg/buildpack/oci_layout_package_internal_test.go;go test ./pkg/buildpack/passes.Output
Before
panic: runtime error: index out of range [N] with length Mwhen packaging or building with a crafted buildpackage.After
A clear error is returned instead of the panic.
Documentation
Related
Resolves #2655