@@ -345,40 +345,32 @@ end
345345
346346# If this fails, io isn't a zip file, io isn't seekable,
347347# or the end of the zip file was corrupted
348+ # Using yauzl method https://github.com/thejoshwolfe/yauzl/blob/51010ce4e8c7e6345efe195e1b4150518f37b393/index.js#L111-L113
348349function find_end_of_central_directory_record (io:: IO ):: Int64
349350 seekend (io)
350351 fsize = position (io)
351- # First assume comment is length zero
352352 fsize ≥ 22 || throw (ArgumentError (" io isn't a zip file. Too small" ))
353- seek (io, fsize- 22 )
354- b = read! (io, zeros (UInt8, 22 ))
355- check_comment_len_valid (b, comment_len) = (
356- EOCDSig == @view (b[end - 21 - comment_len: end - 18 - comment_len]) &&
357- comment_len% UInt8 == b[end - 1 - comment_len] &&
358- UInt8 (comment_len>> 8 ) == b[end - comment_len]
359- )
360- if check_comment_len_valid (b, 0 )
361- # No Zip comment fast path
362- fsize- 22
363- else
364- # There maybe is a Zip comment slow path
365- fsize > 22 || throw (ArgumentError (" io isn't a zip file." ))
366- max_comment_len:: Int = min (0xFFFF , fsize- 22 )
367- seek (io, fsize - (max_comment_len+ 22 ))
368- b = read! (io, zeros (UInt8, (max_comment_len+ 22 )))
369- comment_len = 1
370- while comment_len < max_comment_len && ! check_comment_len_valid (b, comment_len)
371- comment_len += 1
353+ for comment_len in 0 : Int (min (0xFFFF , fsize- 22 ))
354+ seek (io, fsize- 22 - comment_len)
355+ if readle (io, UInt32) != 0x06054b50
356+ continue
372357 end
373- if ! check_comment_len_valid (b, comment_len)
358+ skip (io, 16 )
359+ if readle (io, UInt16) == comment_len
360+ return fsize- 22 - comment_len
361+ else
374362 throw (ArgumentError ("""
375363 io isn't a zip file.
376364 It may be a zip file with a corrupted ending.
377365 """
378366 ))
379367 end
380- fsize- 22 - comment_len
381368 end
369+ throw (ArgumentError ("""
370+ io isn't a zip file.
371+ It may be a zip file with a corrupted ending.
372+ """
373+ ))
382374end
383375
384376function check_EOCD64_used (io:: IO , eocd_offset):: Bool
0 commit comments