archive/zip: fs.ReadDir(..., ".") can return "." and cause fs.WalkDir to stack overflow #50179
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
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: