fix(oci): guard scanBootFiles short namePrefix slice (#63)#64
Merged
Conversation
The import path passes a short placeholder ("import-0") to scanBootFiles
since the layer digest isn't known until the stream is hashed, but the
extract-log sliced [:12] assuming a digest — panicking on any layer that
carries /boot/vmlinuz* or /boot/initrd.img*. Rename the param to namePrefix
(it's a filename prefix, not always a digest) and bound the slice with min().
Other [:12] sites are safe — they all receive the real 64-char hash.
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.
Closes #63.
Problem
cocoon image importpanics on any tar layer containing/boot/vmlinuz*or/boot/initrd.img*:scanBootFilesloggeddigestHex[:12], assuming a 64-char sha256. But the import path (import.go:145) passes a short placeholderfmt.Sprintf("import-%d", j.idx)— the real layer digest isn't known until the stream is fully hashed, andrenameBootFilesrelabels the extracted files to the real digest afterward."import-0"is 8 bytes →[:12]panics, but only once a layer actually carries a boot file (the extract-log is the first slice reached).Fix
digestHex→namePrefixto reflect its real contract: a filename prefix that is a digest on the heal path but a short placeholder on import.min(len(namePrefix), 12).Scope is correct: every other
[:12]inimages/oci(import.go:166/176,process.go:47/88/94/97,boot.go:60) operates on a real 64-char hash (hex.EncodeToString(...)/digest.Hex()) and cannot receive a short label — verified.Test
New
images/oci/boot_test.go:TestScanBootFilesNamePrefixLengths— table over empty / 8-char / 12-char / 64-char prefixes; asserts no panic + correct<prefix>.{vmlinuz,initrd.img}extraction. Reverting the slice guard reproduces the exact[:12] length 8panic on the 8-char case.TestScanBootFilesSkipsNonBoot— confirms non-boot/dirs and.oldsuffixes are skipped.Test plan
go test -race ./...— 24/24 packages greenmake fmt-check && make lint(darwin + linux) — 0 issuesFollow-up (not in this PR)
The
[:12]short-prefix idiom repeats ~11× acrossimages/ociandimages/cloudimg(all currently safe, fed real digests). A sharedutils.ShortHex(s)would make the whole class panic-proof — worth a separate cleanup PR if desired.