Skip to content

Commit

Permalink
zip: Correctly peek for zip64 EOCD
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Feb 22, 2023
1 parent 58b33ab commit bdd6718
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 3 deletions.
Binary file added format/zip/testdata/bigzero-zip.zip
Binary file not shown.
115 changes: 115 additions & 0 deletions format/zip/testdata/bigzero-zip.zip.fqtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# from https://github.com/nih-at/libzip/blob/main/regress/zip64.zip
$ fq -o uncompress=false dv bigzero-zip.zip
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: bigzero-zip.zip (zip) 0x0-0x28f9.7 (10490)
| | | local_files[0:1]: 0x0-0x2892.7 (10387)
| | | [0]{}: local_file 0x0-0x2892.7 (10387)
0x0000|50 4b 03 04 |PK.. | signature: raw bits (valid) 0x0-0x3.7 (4)
0x0000| 14 00 | .. | version_needed: 20 0x4-0x5.7 (2)
| | | flags{}: 0x6-0x7.7 (2)
0x0000| 02 | . | unused0: 0 0x6-0x6 (0.1)
0x0000| 02 | . | strong_encryption: false 0x6.1-0x6.1 (0.1)
0x0000| 02 | . | compressed_patched_data: false 0x6.2-0x6.2 (0.1)
0x0000| 02 | . | enhanced_deflation: false 0x6.3-0x6.3 (0.1)
0x0000| 02 | . | data_descriptor: false 0x6.4-0x6.4 (0.1)
0x0000| 02 | . | compression0: false 0x6.5-0x6.5 (0.1)
0x0000| 02 | . | compression1: true 0x6.6-0x6.6 (0.1)
0x0000| 02 | . | encrypted: false 0x6.7-0x6.7 (0.1)
0x0000| 00 | . | reserved0: 0 0x7-0x7.1 (0.2)
0x0000| 00 | . | mask_header_values: false 0x7.2-0x7.2 (0.1)
0x0000| 00 | . | reserved1: false 0x7.3-0x7.3 (0.1)
0x0000| 00 | . | language_encoding: false 0x7.4-0x7.4 (0.1)
0x0000| 00 | . | unused1: 0 0x7.5-0x7.7 (0.3)
0x0000| 08 00 | .. | compression_method: "deflated" (8) 0x8-0x9.7 (2)
| | | last_modification_date{}: 0xa-0xb.7 (2)
0x0000| c8 | . | hours: 25 0xa-0xa.4 (0.5)
0x0000| c8 78 | .x | minutes: 3 0xa.5-0xb.2 (0.6)
0x0000| 78 | x | seconds: 24 0xb.3-0xb.7 (0.5)
| | | last_modification_time{}: 0xc-0xd.7 (2)
0x0000| 84 | . | year: 66 0xc-0xc.6 (0.7)
0x0000| 84 45 | .E | month: 2 0xc.7-0xd.2 (0.4)
0x0000| 45 | E | day: 5 0xd.3-0xd.7 (0.5)
0x0000| 54 81| T.| crc32_uncompressed: 0xae158154 0xe-0x11.7 (4)
0x0010|15 ae |.. |
0x0010| 4e 28 00 00 | N(.. | compressed_size: 10318 0x12-0x15.7 (4)
0x0010| b9 9a 3f 00 | ..?. | uncompressed_size: 4168377 0x16-0x19.7 (4)
0x0010| 0b 00 | .. | file_name_length: 11 0x1a-0x1b.7 (2)
0x0010| 1c 00 | .. | extra_field_length: 28 0x1c-0x1d.7 (2)
0x0010| 62 69| bi| file_name: "bigzero.zip" 0x1e-0x28.7 (11)
0x0020|67 7a 65 72 6f 2e 7a 69 70 |gzero.zip |
| | | extra_fields[0:2]: 0x29-0x44.7 (28)
| | | [0]{}: extra_field 0x29-0x35.7 (13)
0x0020| 55 54 | UT | header_id: 0x5455 (extended timestamp) 0x29-0x2a.7 (2)
0x0020| 09 00 | .. | data_size: 9 0x2b-0x2c.7 (2)
0x0020| 03 57 6a| .Wj| data: raw bits 0x2d-0x35.7 (9)
0x0030|80 54 7e 6a 80 54 |.T~j.T |
| | | [1]{}: extra_field 0x36-0x44.7 (15)
0x0030| 75 78 | ux | header_id: 0x7875 (UNIX UID/GID) 0x36-0x37.7 (2)
0x0030| 0b 00 | .. | data_size: 11 0x38-0x39.7 (2)
0x0030| 01 04 74 00 00 00| ..t...| data: raw bits 0x3a-0x44.7 (11)
0x0040|04 14 00 00 00 |..... |
0x0040| ed dd bf aa 03 df bf df e7 ef 9c| ...........| compressed: raw bits 0x45-0x2892.7 (10318)
0x0050|59 39 e7 60 8c fe 40 94 66 1a 5d 40 4e af 46 9c|Y9.`..@.f.]@N.F.|
* |until 0x2892.7 (10318) | |
| | | central_directories[0:1]: 0x2893-0x28e3.7 (81)
| | | [0]{}: central_directory 0x2893-0x28e3.7 (81)
0x2890| 50 4b 01 02 | PK.. | signature: raw bits (valid) 0x2893-0x2896.7 (4)
0x2890| 1e 03 | .. | version_made_by: 798 0x2897-0x2898.7 (2)
0x2890| 14 00 | .. | version_needed: 20 0x2899-0x289a.7 (2)
| | | flags{}: 0x289b-0x289c.7 (2)
0x2890| 02 | . | unused0: 0 0x289b-0x289b (0.1)
0x2890| 02 | . | strong_encryption: false 0x289b.1-0x289b.1 (0.1)
0x2890| 02 | . | compressed_patched_data: false 0x289b.2-0x289b.2 (0.1)
0x2890| 02 | . | enhanced_deflation: false 0x289b.3-0x289b.3 (0.1)
0x2890| 02 | . | data_descriptor: false 0x289b.4-0x289b.4 (0.1)
0x2890| 02 | . | compression0: false 0x289b.5-0x289b.5 (0.1)
0x2890| 02 | . | compression1: true 0x289b.6-0x289b.6 (0.1)
0x2890| 02 | . | encrypted: false 0x289b.7-0x289b.7 (0.1)
0x2890| 00 | . | reserved0: 0 0x289c-0x289c.1 (0.2)
0x2890| 00 | . | mask_header_values: false 0x289c.2-0x289c.2 (0.1)
0x2890| 00 | . | reserved1: false 0x289c.3-0x289c.3 (0.1)
0x2890| 00 | . | language_encoding: false 0x289c.4-0x289c.4 (0.1)
0x2890| 00 | . | unused1: 0 0x289c.5-0x289c.7 (0.3)
0x2890| 08 00 | .. | compression_method: "deflated" (8) 0x289d-0x289e.7 (2)
| | | last_modification_date{}: 0x289f-0x28a0.7 (2)
0x2890| c8| .| hours: 25 0x289f-0x289f.4 (0.5)
0x2890| c8| .| minutes: 3 0x289f.5-0x28a0.2 (0.6)
0x28a0|78 |x |
0x28a0|78 |x | seconds: 24 0x28a0.3-0x28a0.7 (0.5)
| | | last_modification_time{}: 0x28a1-0x28a2.7 (2)
0x28a0| 84 | . | year: 66 0x28a1-0x28a1.6 (0.7)
0x28a0| 84 45 | .E | month: 2 0x28a1.7-0x28a2.2 (0.4)
0x28a0| 45 | E | day: 5 0x28a2.3-0x28a2.7 (0.5)
0x28a0| 54 81 15 ae | T... | crc32_uncompressed: 0xae158154 0x28a3-0x28a6.7 (4)
0x28a0| 4e 28 00 00 | N(.. | compressed_size: 10318 0x28a7-0x28aa.7 (4)
0x28a0| b9 9a 3f 00 | ..?. | uncompressed_size: 4168377 0x28ab-0x28ae.7 (4)
0x28a0| 0b| .| file_name_length: 11 0x28af-0x28b0.7 (2)
0x28b0|00 |. |
0x28b0| 18 00 | .. | extra_field_length: 24 0x28b1-0x28b2.7 (2)
0x28b0| 00 00 | .. | file_comment_length: 0 0x28b3-0x28b4.7 (2)
0x28b0| 00 00 | .. | disk_number_where_file_starts: 0 0x28b5-0x28b6.7 (2)
0x28b0| 00 00 | .. | internal_file_attributes: 0 0x28b7-0x28b8.7 (2)
0x28b0| 00 00 b4 81 | .... | external_file_attributes: 2176057344 0x28b9-0x28bc.7 (4)
0x28b0| 00 00 00| ...| relative_offset_of_local_file_header: 0 0x28bd-0x28c0.7 (4)
0x28c0|00 |. |
0x28c0| 62 69 67 7a 65 72 6f 2e 7a 69 70 | bigzero.zip | file_name: "bigzero.zip" 0x28c1-0x28cb.7 (11)
| | | extra_fields[0:2]: 0x28cc-0x28e3.7 (24)
| | | [0]{}: extra_field 0x28cc-0x28d4.7 (9)
0x28c0| 55 54 | UT | header_id: 0x5455 (extended timestamp) 0x28cc-0x28cd.7 (2)
0x28c0| 05 00| ..| data_size: 5 0x28ce-0x28cf.7 (2)
0x28d0|03 57 6a 80 54 |.Wj.T | data: raw bits 0x28d0-0x28d4.7 (5)
| | | [1]{}: extra_field 0x28d5-0x28e3.7 (15)
0x28d0| 75 78 | ux | header_id: 0x7875 (UNIX UID/GID) 0x28d5-0x28d6.7 (2)
0x28d0| 0b 00 | .. | data_size: 11 0x28d7-0x28d8.7 (2)
0x28d0| 01 04 74 00 00 00 04| ..t....| data: raw bits 0x28d9-0x28e3.7 (11)
0x28e0|14 00 00 00 |.... |
| | | file_comment: "" 0x28e4-NA (0)
| | | end_of_central_directory_record{}: 0x28e4-0x28f9.7 (22)
0x28e0| 50 4b 05 06 | PK.. | signature: raw bits (valid) 0x28e4-0x28e7.7 (4)
0x28e0| 00 00 | .. | disk_nr: 0 0x28e8-0x28e9.7 (2)
0x28e0| 00 00 | .. | central_directory_start_disk_nr: 0 0x28ea-0x28eb.7 (2)
0x28e0| 01 00 | .. | nr_of_central_directory_records_on_disk: 1 0x28ec-0x28ed.7 (2)
0x28e0| 01 00| ..| nr_of_central_directory_records: 1 0x28ee-0x28ef.7 (2)
0x28f0|51 00 00 00 |Q... | size_of_central_directory: 81 0x28f0-0x28f3.7 (4)
0x28f0| 93 28 00 00 | .(.. | offset_of_start_of_central_directory: 10387 0x28f4-0x28f7.7 (4)
0x28f0| 00 00| | ..| | comment_length: 0 0x28f8-0x28f9.7 (2)
| | | comment: "" 0x28fa-NA (0)
6 changes: 3 additions & 3 deletions format/zip/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func zipDecode(d *decode.D) any {
d.SeekAbs(d.Len())

// TODO: better EOCD probe
p, _, err := d.TryPeekFind(32, -8, 10000, func(v uint64) bool {
p, _, err := d.TryPeekFind(32, -8, 128*8, func(v uint64) bool {
return v == uint64(endOfCentralDirectoryRecordSignatureN)
})
if err != nil {
Expand All @@ -177,10 +177,10 @@ func zipDecode(d *decode.D) any {
})

// is there a zip64 end of central directory locator?
p, _, err = d.TryPeekFind(32, -8, 10000, func(v uint64) bool {
p, _, err = d.TryPeekFind(32, -8, 128*8, func(v uint64) bool {
return v == uint64(endOfCentralDirectoryLocatorSignatureN)
})
if err == nil {
if err == nil && p != -1 {
d.SeekRel(p)

var offsetEOCD uint64
Expand Down

0 comments on commit bdd6718

Please sign in to comment.