wslc container cp silently produces an empty file when the source is a symlink
Windows Version
Microsoft Windows [Version 10.0.26220.8764]
WSL Version
2.9.4.0
Are you using WSL 1 or WSL 2?
- [X] WSL 2
- [ ] WSL 1
Kernel Version
6.18.35.2-1
Distro Version
Not a distro install — reproduced against the container image mcr.microsoft.com/azurelinux/base/core:3.0.
Other Software
None. This is wslc, WSL's own container CLI.
Repro Steps
wslc image pull mcr.microsoft.com/azurelinux/base/core:3.0
wslc container run -d --name repro mcr.microsoft.com/azurelinux/base/core:3.0 \
sh -c "mkdir -p /w && printf 'REAL-CONTENT' > /w/real.txt && ln -s /w/real.txt /w/link.txt && sleep 120"
# In the guest both entries are as expected:
# -rw-r--r-- 1 root root 12 real.txt
# lrwxrwxrwx 1 root root 11 link.txt -> /w/real.txt
wslc container cp repro:/w/real.txt ./real.out # control
wslc container cp repro:/w/link.txt ./link.out # the bug
Expected Behavior
Copying a symlink out of a container should do one of three things: preserve the link, follow it and copy the target's bytes, or fail with a diagnostic. Any of those is workable for a caller. The docker CLI, whose surface wslc container cp mirrors, preserves the link entry.
Actual Behavior
wslc container cp exits 0, writes nothing to stderr, and creates a 0-byte regular file. The result is indistinguishable from a file that was legitimately empty.
cp real.txt -> exit=0 stderr=[] size=12 content=[REAL-CONTENT]
cp link.txt -> exit=0 stderr=[] size=0 content=[]
Three observations narrow this down:
-a/--archivemakes no difference.- It is not a general absence of error reporting. The same command fails correctly elsewhere: a directory copied to a file path returns exit 1 with
Cannot copy a directory to a file path. Use a directory target (with trailing separator) instead. Error code: E_FAIL, and a nonexistent source returns exit 1 withCould not find the file /w/nope.txt in container <id>. Error code: ERROR_PATH_NOT_FOUNDand creates no file. Only the symlink case reports success while producing nothing. - It is not containment. A link pointing inside the copied tree behaves identically to one pointing outside it, so this does not look like a deliberate refusal to let a copy escape the container.
The guest has the information needed to act on it: stat -c '%F %s' /w/link.txt reports symbolic link 11.
The practical impact is that a caller cannot distinguish this from an empty file, so the failure propagates silently into whatever consumes the copy. The only workaround is to exec into the container and stat the path first, which requires the image to contain a shell — something cp itself does not need.
Diagnostic Logs
None attached; the repro above is deterministic and requires no tracing.
Disclosure: this report's text was co-authored with an AI assistant. The repro was executed against a real wslc install and the outputs quoted are actual command results, not generated examples. The content has been reviewed and approved by me before filing.
Logs are required for review from WSL team
If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.
How to collect WSL logs
Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1
The script will output the path of the log file once done.
If this is a networking issue, please use .\collect-wsl-logs.ps1 -LogProfile networking instead, following the instructions in Collect WSL logs for networking issues
Once completed please upload the output files to this GitHub issue.
See Collect WSL logs (recommended method).
If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.
Thanks for the precise repro — deterministic and easy to reason about. A few observations that might help the WSL team narrow it down:
Working hypothesis for the root cause: symlink handling is dropped somewhere in the copy/extract path.
wslc container cp on a symlink whose target is a regular file: the guest stat reports a link (size 11 = length of the target path string), but what lands on disk is a 0-byte regular file. The signature looks like the archive member is created as a regular file with the symlink's type flag lost — the 11-byte target string isn't being treated as a link target at all. This is consistent with the tar member's linkname field being ignored on extraction.
The evidence you've already gathered fits: repro:/w/real.txt copies its 12 bytes correctly (regular file), while the size-11 symlink becomes 0 bytes — the size being carried over as the target string length rather than the file being dereferenced.
Containment theory ruled out cleanly (good test): an in-tree link behaves identically to an out-of-tree one, so this isn't a deliberate refusal to copy outside the container — it's a missing symlink case in the extractor.
Practical impact is worth restating: exit 0 + 0-byte output is indistinguishable from a legitimately-empty file, so downstream consumers silently ingest garbage. The only reliable workaround today is exec+stat first, which (as you note) requires a shell — something cp itself shouldn't need.
For anyone hitting this before it's fixed, I keep a docker cp / wslc container cp command comparison (including symlink behaviour notes) at https://wslcontainers.com/commands/cp/ — happy to update it with the actual fix once it lands.
Feature request for the WSL team: wslc container cp should at minimum fail with a diagnostic when the source is a symlink it can't preserve, rather than returning success with an empty file. Matching docker's behaviour of preserving the link entry would also be acceptable.
Attempted to repro following the provided instructions. Copying a symlink out of a container now results in the link being copied correctly, however, the file the link was pointing at does not get copied. Running wslc container cp repro:/w/link.txt ./link.out results in a link from link.out to /w/file.txt. file.txt does not get copied as well, so the link still does not work. It is likely we will not change this behavior as it aligns with what Docker does.
Docker Repro:
> docker container run -d --name repro mcr.microsoft.com/azurelinux/base/core:3.0 sh -c "mkdir -p /w && printf 'REAL-CONTENT' > /w/real.txt && ln -s /w/real.txt /w/link.txt && sleep 120"
3156cd5f57ab1313e777d13eb503465590c4395bbf3dece8370c47e67c2ca007
> docker container cp repro:/w/real.txt ./real.out
Successfully copied 12B (transferred 2.05kB) to C:\Users\gavingarzia\repos\WSL\tmp\real.out
> docker container cp repro:/w/link.txt ./link.out
Successfully copied 11B (transferred 1.54kB) to C:\Users\gavingarzia\repos\WSL\tmp\link.out
> ls -l
total 12
lrwxrwxrwx 1 gavingarzia gavingarzia 0 Oct 9 15:26 link.out -> /w/real.txt
-rwxrwxrwx 1 gavingarzia gavingarzia 12 Oct 9 15:26 real.out
> cat .\real.out
REAL-CONTENT
> cat .\link.out
cat.cmd: .\link.out: The filename, directory name, or volume label syntax is incorrect.
To follow symlinks when copying from a container use the --follow-link (-L) flag (added #41501)
> wslc container cp -L repro:/tmp/link.txt ./followed-link.txt
> ls -l
total 12
-rwxrwxrwx 1 gavingarzia gavingarzia 12 Oct 9 15:05 followed-link.txt
lrwxrwxrwx 1 gavingarzia gavingarzia 0 Oct 9 15:20 link.txt -> file.txt
> cat .\followed-link.txt
REAL-CONTENT
Additionally, note that symlinks on windows have a size of 0, that does not mean it was copied incorrectly. To demonstrate I created a symlink in powershell with both the ln and New-Item -ItemType SymbolicLink commands and both links are functional and show a size of 0
> ln -s real.out link.txt
> cat link.txt
REAL-CONTENT
> New-Item -ItemType SymbolicLink -Path link2.txt -Target real.out
Directory: C:\Users\gavingarzia\repos\WSL\tmp
Mode LastWriteTime Length Name
---- ------------- ------ ----
la--- 10/9/2026 3:47 PM 0 link2.txt -> real.out
> cat link2.txt
REAL-CONTENT
> ls -l
total 12
lrwxrwxrwx 1 gavingarzia gavingarzia 0 Oct 9 15:37 link.txt -> real.out
lrwxrwxrwx 1 gavingarzia gavingarzia 0 Oct 9 15:47 link2.txt -> real.out
-rwxrwxrwx 1 gavingarzia gavingarzia 12 Oct 9 15:26 real.out
Thanks for checking this. I agree with keeping this issue closed: the original silent-success failure no longer reproduces with WSLC 3.0.3.0.
One clarification for the historical record: the 2.9.4 report concerned an empty regular file, rather than a preserved Windows symlink displaying a length of zero. The 2.9.4 file-destination implementation created a regular file with CreateFileW and redirected tar.exe -xf ... -O into it. Repeating that extraction step against a symlink archive produces exit 0, empty stderr, and zero output bytes, which explains the original symptom.
The relevant default-copy correction appears in #41668: extraction now stages and moves the filesystem entry instead of writing its content through stdout. That implementation is present in both 3.0.2 and 3.0.3. #41501 added the useful -L option, but retained the old default file-destination extraction path.
Fresh checks with WSLC 3.0.3.0 and mcr.microsoft.com/azurelinux/base/core:3.0 confirmed:
- Regular files copy correctly, including the 12-byte
REAL-CONTENTcontrol; genuinely empty files remain distinguishable. -Lcopies the correct 12 bytes for both absolute and relative source symlinks.- Copying a symlink to stdout as a tar archive preserves its symlink type and target.
- Ordinary host-side symlink extraction in my test context fails explicitly with exit 1 and a
tar.exediagnostic, without creating the destination file. Standalone tar extraction also fails there, and native Windows symlink creation reports WinError 1314 (required privilege not held), so I could not independently verify successful host-side link preservation in that context. Crucially, it no longer reports success while creating an empty regular file.
Preserving the link without also copying its target is an acceptable outcome, as stated in the original report. The remaining local extraction/privilege limitation is separate from the silent-success defect tracked here. Thanks for the improvements; no reopening requested.