Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Properly identify POSIX uncompressed tars #12011

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ def stage
# Use more than 4 characters to not clash with magicbytes
magic_bytes = "____pkg"
else
# get the first six bytes
File.open(@tarball_path) { |f| magic_bytes = f.read(6) }
# get 6 bytes magic number
# (POSIX tar magic has a 257 bytes offset)
File.open(@tarball_path) { |f| magic_bytes = f.read(262) }
end

# magic numbers stolen from /usr/share/file/magic/
case magic_bytes
when /^PK\003\004/ # .zip archive
quiet_safe_system '/usr/bin/unzip', {:quiet_flag => '-qq'}, @tarball_path
chdir
when /^\037\213/, /^BZh/, /^\037\235/ # gzip/bz2/compress compressed
when /^.{257}ustar/, /^\037\213/, /^BZh/, /^\037\235/ # uncompressed/gzip/bz2/compress
# TODO check if it's really a tar archive
safe_system '/usr/bin/tar', 'xf', @tarball_path
chdir
Expand Down