apk/installed: guard ParseInstalled against short lines - #2328
Merged
stevebeattie merged 2 commits intoAug 4, 2026
Merged
Conversation
The per-line check used len(line) > 1, so a single-character line skipped the delimiter check and then line[2:] sliced out of range and panicked (slice bounds out of range [2:1]) instead of returning a parse error. This is reachable when parsing an apk installed database, for example a base image's installed file in pkg/baseimg, so a corrupt or malformed entry crashes apko rather than failing cleanly. Guard the length before slicing, matching the len(line) < 2 check the sibling APKINDEX parser already does, and add a regression test. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
A single-character line in an apk installed database panics
ParseInstalledinstead of failing cleanly.The per-line check is
if len(line) > 1 && line[1:2] != ":", so a length-1 line short-circuits past the delimiter check, and thenval := line[2:]slices out of range and panics withslice bounds out of range [2:1]. This is reachable wherever we parse an installed database:pkg/baseimg.Newruns it over a base image's installed file (base_image.go:106), andGetInstalledreads it off the apk filesystem. A corrupt or malformed entry (a strayP) takes down apko rather than returning a parse error.The sibling APKINDEX parser already guards this with
if len(line) < 2. This does the same before slicing, so a short line becomes a normal parse error, and adds a regression test ininstalled_test.go.Verified
go test ./pkg/apk/apk/...: the new test panics on the old code and passes with the guard, and the rest of the package still passes.