Repository navigation
Conversation
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.
Map downloads extract nothing on any machine without "/data/media/0" since aa04ba4. "GetBaseOpPath()" returns "." there, and "safeJoin" then rejects every archive entry as escaping the destination, so a download finishes with 0 of N files and no error shown. On a comma device the base path is "/data/media/0/osm" and nothing changes.
This keeps the tar-slip check but does it with "filepath.Rel" and "filepath.IsLocal" instead of a string prefix, which works for relative and absolute bases.
Audit report
Cause
"safeJoin" builds "filepath.Clean(base) + "/"" and checks that the cleaned target starts with it. "filepath.Clean(".")" is ".", so the prefix becomes "./", but "filepath.Join(".", "offline/46/-124/")" is "offline/46/-124" with no "./" in front. Every real entry fails the prefix check. The existing "safeJoin" tests all use "/data/media/0/osm" as the base, so they couldn't catch it.
Fix
"filepath.Rel(base, target)" gives the target's path relative to the base, and "filepath.IsLocal" rejects anything that leaves it ("..", "../x" and so on). An absolute entry name like "/etc/shadow" is still joined under the base, so it stays allowed the way "TestSafeJoinAllowsNormalEntries" expects. "IsLocal" has been in Go since 1.20 and go.mod is 1.25.1.
Testing
Not covered
I didn't add a regression test with base "." to the existing table, to keep the change to the fix itself.