Skip to content

fix(cp): return non-nil Content from dry-run CopyFromContainer - #13982

Open
glours wants to merge 1 commit into
docker:mainfrom
glours:fix-panic-dryrun-cp
Open

fix(cp): return non-nil Content from dry-run CopyFromContainer#13982
glours wants to merge 1 commit into
docker:mainfrom
glours:fix-panic-dryrun-cp

Conversation

@glours

@glours glours commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What I did
The caller in pkg/compose/cp.go unconditionally defers res.Content.Close() once the call succeeds. The dry-run client returned a zero-value result with a nil Content reader, so docker compose cp --dry-run <ctr>:<path> <dst> panicked with a nil pointer dereference. Return an empty NopCloser instead, matching the pattern already used for the other stream results in this file.

Related issue
https://docker.atlassian.net/browse/DDB-589

(not mandatory) A picture of a cute animal, if possible in relation to what you did
image

The caller in pkg/compose/cp.go unconditionally defers
res.Content.Close() once the call succeeds. The dry-run client
returned a zero-value result with a nil Content reader, so
`docker compose cp --dry-run <ctr>:<path> <dst>` panicked with a
nil pointer dereference. Return an empty NopCloser instead, matching
the pattern already used for the other stream results in this file.

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
@glours
glours requested review from a team as code owners July 29, 2026 12:49
@glours
glours requested a review from ndeloof July 29, 2026 12:49
@glours glours self-assigned this Jul 29, 2026

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

One medium-severity confirmed finding: the PR correctly fixes the nil-pointer panic by returning a non-nil Content, but the Stat field in the returned CopyFromContainerResult remains zero-valued. Since ContainerStatPath is already called (and its result discarded), the fix is straightforward: capture and return the Stat so the caller's res.Stat.Mode.IsDir() check works correctly for directory sources in dry-run mode.

Comment thread pkg/dryrun/dryrunclient.go
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/dryrun/dryrunclient.go 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants