fix: add bounds checking to addendum layer mutations to prevent panic #1715
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 #1646
Based on PR by @Gnoale here - GoogleContainerTools/kaniko#2538. From the PR there - "It seems that the addendums slice index is incremented twice in cases there is an empty layer in the history" <-- this seems to lead to a possibly unexpected case where addendumIdx > len(addendums) which makes addendums[addendumIdx] panic
Adding context from the above issue in the description below vvv:
Currently in kaniko v1.9.2+ (which uses go-containerregistry v0.14.0+) a panic occurs when attempting to call go-containerregistry related to the code here:
https://github.com/google/go-containerregistry/blob/main/pkg/v1/mutate/mutate.go#L405
No errors using the same dockerfile with kaniko v1.9.1 which uses go-containerregistry v0.8.1-0.20220507185902-82405e5dfa82
The likely cuplrit is commit 9db616f, since the error happens in mutate.Time after trying to index the addendums slice. The PR adds an additional bounds check on
addendums
before mutating.