Recognize 7z files by magic bytes, not filename
This commit is contained in:
		
							parent
							
								
									12932a51b3
								
							
						
					
					
						commit
						df29049222
					
				@ -181,20 +181,20 @@ class Pathname
 | 
				
			|||||||
    # POSIX tar magic has a 257 byte offset
 | 
					    # POSIX tar magic has a 257 byte offset
 | 
				
			||||||
    # magic numbers stolen from /usr/share/file/magic/
 | 
					    # magic numbers stolen from /usr/share/file/magic/
 | 
				
			||||||
    case open { |f| f.read(262) }
 | 
					    case open { |f| f.read(262) }
 | 
				
			||||||
    when /^PK\003\004/n   then :zip
 | 
					    when /^PK\003\004/n         then :zip
 | 
				
			||||||
    when /^\037\213/n     then :gzip
 | 
					    when /^\037\213/n           then :gzip
 | 
				
			||||||
    when /^BZh/n          then :bzip2
 | 
					    when /^BZh/n                then :bzip2
 | 
				
			||||||
    when /^\037\235/n     then :compress
 | 
					    when /^\037\235/n           then :compress
 | 
				
			||||||
    when /^.{257}ustar/n  then :tar
 | 
					    when /^.{257}ustar/n        then :tar
 | 
				
			||||||
    when /^\xFD7zXZ\x00/n then :xz
 | 
					    when /^\xFD7zXZ\x00/n       then :xz
 | 
				
			||||||
    when /^Rar!/n         then :rar
 | 
					    when /^Rar!/n               then :rar
 | 
				
			||||||
 | 
					    when /^7z\xBC\xAF\x27\x1C/n then :p7zip
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      # This code so that bad-tarballs and zips produce good error messages
 | 
					      # This code so that bad-tarballs and zips produce good error messages
 | 
				
			||||||
      # when they don't unarchive properly.
 | 
					      # when they don't unarchive properly.
 | 
				
			||||||
      case extname
 | 
					      case extname
 | 
				
			||||||
        when ".tar.gz", ".tgz", ".tar.bz2", ".tbz" then :tar
 | 
					      when ".tar.gz", ".tgz", ".tar.bz2", ".tbz" then :tar
 | 
				
			||||||
        when ".zip" then :zip
 | 
					      when ".zip" then :zip
 | 
				
			||||||
        when ".7z" then :p7zip
 | 
					 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user