-
Notifications
You must be signed in to change notification settings - Fork 18k
archive/zip: fs.ReadDir(..., ".") can return "." and cause fs.WalkDir to stack overflow #50179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Smaller reproducer
|
I tried to run the reproducer on Go 1.21 and it looks like this has been solved, the output is:
as expected. |
When I run the test case in a terminal, not in the Go playground, I see it print
followed by a stack trace. |
As far as I know, a lone |
I don't think we should change anything in io/fs. I suppose the archive/zip |
Change https://go.dev/cl/656495 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Self contained reproducer: https://go.dev/play/p/APYHtDb8IVg
We were attempting to scan a JAR (which are ZIPs) using archive/zip with fs.WalkDir and found that it was crashing our program. Our code looks something like this:
After digging into it, it appeared that our ZIP has an entry for "." and
fs.ReadDir(zr, ".")
returned "." as a result, causing fs.WalkDir to walk "." over and over again.We worked around this by wrapping the *zip.Reader in a struct that overrode ReadDir()
What did you expect to see?
Running the playground link above, I'd expect fs.WalkDir to return normally.
What did you see instead?
Instead it stack overflows.
The text was updated successfully, but these errors were encountered: