Skip to content

Commit cc52619

Browse files
committed
Fix trailing whitespace in zip files
1 parent b0ac7a7 commit cc52619

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

lib/zip/zip.rb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,8 @@ def read_e_o_c_d(io) #:nodoc:
12591259
@cdirOffset = ZipEntry::read_zip_long(buf)
12601260
commentLength = ZipEntry::read_zip_short(buf)
12611261
@comment = buf.read(commentLength)
1262+
# remove trailing \n or \f or \r symbol
1263+
buf.gsub!(/\s/,'')
12621264
raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0
12631265
end
12641266

@@ -1284,26 +1286,12 @@ def get_e_o_c_d(io) #:nodoc:
12841286
io.seek(-MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE, IO::SEEK_END)
12851287
rescue Errno::EINVAL
12861288
io.seek(0, IO::SEEK_SET)
1287-
rescue Errno::EFBIG # FreeBSD 4.9 raise Errno::EFBIG instead of Errno::EINVAL
1288-
io.seek(0, IO::SEEK_SET)
1289-
end
1290-
1291-
# 'buf = io.read' substituted with lump of code to work around FreeBSD 4.5 issue
1292-
retried = false
1293-
buf = nil
1294-
begin
1295-
buf = io.read
1296-
rescue Errno::EFBIG # FreeBSD 4.5 may raise Errno::EFBIG
1297-
raise if (retried)
1298-
retried = true
1299-
1300-
io.seek(0, IO::SEEK_SET)
1301-
retry
13021289
end
13031290

1291+
buf = io.read
13041292
sigIndex = buf.rindex([END_OF_CENTRAL_DIRECTORY_SIGNATURE].pack('V'))
13051293
raise ZipError, "Zip end of central directory signature not found" unless sigIndex
1306-
buf=buf.slice!((sigIndex+4)...(buf.size))
1294+
buf=buf.slice!((sigIndex+4)..(buf.size))
13071295
def buf.read(count)
13081296
slice!(0, count)
13091297
end

0 commit comments

Comments
 (0)