fix(dpkg): handle missing files in distroless status.d gracefully#1808
Open
fix(dpkg): handle missing files in distroless status.d gracefully#1808
Conversation
5 tasks
aa2b5c4 to
e6fa003
Compare
The distroless scanner failed the entire scan when a file in status.d/ could not be opened (e.g., a dangling symlink to a .list file in info/). Now skips missing files with a warning instead of aborting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Yuval Kashtan <yuvalkashtan@gmail.com>
e6fa003 to
87ea190
Compare
hdonnay
requested changes
Apr 24, 2026
Comment on lines
+74
to
+120
| now := time.Now() | ||
|
|
||
| // Build a tar with: | ||
| // - var/lib/dpkg/status.d/gcc-14-base (valid control file) | ||
| // - var/lib/dpkg/status.d/gcc-14-base.list (symlink to missing ../info/gcc-14-base.list) | ||
| controlData := []byte("Package: gcc-14-base\nVersion: 14.2.0-19\nArchitecture: amd64\nSource: gcc-14\n\n") | ||
| buf := &bytes.Buffer{} | ||
| h := sha256.New() | ||
| tw := tar.NewWriter(io.MultiWriter(buf, h)) | ||
|
|
||
| for _, dir := range []string{ | ||
| "var/lib/dpkg/", | ||
| "var/lib/dpkg/status.d/", | ||
| } { | ||
| if err := tw.WriteHeader(&tar.Header{ | ||
| Typeflag: tar.TypeDir, | ||
| Name: dir, | ||
| Mode: 0755, | ||
| ModTime: now, | ||
| }); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| if err := tw.WriteHeader(&tar.Header{ | ||
| Typeflag: tar.TypeReg, | ||
| Name: "var/lib/dpkg/status.d/gcc-14-base", | ||
| Size: int64(len(controlData)), | ||
| Mode: 0644, | ||
| ModTime: now, | ||
| }); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if _, err := tw.Write(controlData); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := tw.WriteHeader(&tar.Header{ | ||
| Typeflag: tar.TypeSymlink, | ||
| Name: "var/lib/dpkg/status.d/gcc-14-base.list", | ||
| Linkname: "../info/gcc-14-base.list", | ||
| Mode: 0644, | ||
| ModTime: now, | ||
| }); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := tw.Close(); err != nil { | ||
| t.Fatal(err) | ||
| } |
| } | ||
|
|
||
| func TestDistrolessMissingListFile(t *testing.T) { | ||
| ctx := context.Background() |
|
|
||
| desc := claircore.LayerDescription{ | ||
| URI: "file:///dev/null", | ||
| Digest: fmt.Sprintf("sha256:%x", h.Sum(nil)), |
Member
There was a problem hiding this comment.
This doesn't need the "correct" sha256, just a valid sha256, so this could be replaced with sha256:aaa....
Use test.Logging, test.GenerateFixture, and test.AnyDescription instead of hand-rolled context, sha256 computation, and in-memory tar buffer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
Summary
status.d/cannot be opened (e.g., a dangling symlink to a.listfile ininfo/that doesn't exist in the layer)status.d/to verify the fixTest plan
TestDistrolessMissingListFilepasses — constructs a layer with a dangling symlink and verifies the scan succeeds🤖 Generated with Claude Code