Skip to content
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

Allow tilde in zip entry names #391

Merged
merged 1 commit into from May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/zip/entry.rb
Expand Up @@ -118,7 +118,7 @@ def name_safe?
return false unless cleanpath.relative?
root = ::File::SEPARATOR
naive_expanded_path = ::File.join(root, cleanpath.to_s)
cleanpath.expand_path(root).to_s == naive_expanded_path
::File.absolute_path(cleanpath.to_s, root) == naive_expanded_path
end

def local_entry_offset #:nodoc:all
Expand Down
Binary file added test/data/path_traversal/tilde.zip
Binary file not shown.
7 changes: 7 additions & 0 deletions test/path_traversal_test.rb
Expand Up @@ -131,4 +131,11 @@ def test_entry_name_with_relative_symlink
refute File.exist?('/tmp/file.txt')
end
end

def test_entry_name_with_tilde
in_tmpdir do
extract_path_traversal_zip 'tilde.zip'
assert File.exist?('~tilde~')
end
end
end