Skip to content

Commit

Permalink
Merge pull request #391 from jdleesmiller/fix-expand-path
Browse files Browse the repository at this point in the history
Allow tilde in zip entry names
  • Loading branch information
jdleesmiller committed May 23, 2019
2 parents 249775f + ad15c3c commit ef516bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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

0 comments on commit ef516bd

Please sign in to comment.