Skip to content

Commit

Permalink
Add checks for illegal/non-portable filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
pmqs committed Dec 27, 2023
1 parent 07f90ce commit 49735a7
Show file tree
Hide file tree
Showing 50 changed files with 1,804 additions and 230 deletions.
412 changes: 236 additions & 176 deletions MANIFEST

Large diffs are not rendered by default.

227 changes: 174 additions & 53 deletions bin/zipdetails

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion t/002-main.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use Fcntl qw(SEEK_SET);

my $tests_per_zip = 6 ;
my $tests_per_zip_full = $tests_per_zip * 2 * 3 * 2 ;
plan tests => 181 * $tests_per_zip_full ;
plan tests => 193 * $tests_per_zip_full ;

sub run;
sub compareWithGolden;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perl -MIO::Compress::Zip=:all -e 'zip \"abcd" => "test.zip", Minimal => 1, Stream => 1, Name => q[abc/]'
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

0000 LOCAL HEADER #1 04034B50 (67324752)
0004 Extract Zip Spec 14 (20) '2.0'
0005 Extract OS 00 (0) 'MS-DOS'
0006 General Purpose Flag 0008 (8)
[Bits 1-2] 0 'Normal Compression'
[Bit 3] 1 'Streamed'
0008 Compression Method 0008 (8) 'Deflated'
000A Last Mod Date/Time 579B5B7C (1469799292) 'Wed Dec 27 11:27:56 2023'
000E CRC 00000000 (0)
0012 Compressed Size 00000000 (0)
0016 Uncompressed Size 00000000 (0)
001A Filename Length 0004 (4)
001C Extra Length 0000 (0)
001E Filename 'abc/'
0022 PAYLOAD KLJN..

0028 DATA DESCRIPTOR 08074B50 (134695760)
002C CRC ED82CD11 (3984772369)
0030 Compressed Size 00000006 (6)
0034 Uncompressed Size 00000004 (4)
#
# WARNING: Directory 'abc/' must not have a payload
#

0038 CENTRAL HEADER #1 02014B50 (33639248)
003C Created Zip Spec 14 (20) '2.0'
003D Created OS 03 (3) 'Unix'
003E Extract Zip Spec 14 (20) '2.0'
003F Extract OS 00 (0) 'MS-DOS'
0040 General Purpose Flag 0008 (8)
[Bits 1-2] 0 'Normal Compression'
[Bit 3] 1 'Streamed'
0042 Compression Method 0008 (8) 'Deflated'
0044 Last Mod Date/Time 579B5B7C (1469799292) 'Wed Dec 27 11:27:56 2023'
0048 CRC ED82CD11 (3984772369)
004C Compressed Size 00000006 (6)
0050 Uncompressed Size 00000004 (4)
0054 Filename Length 0004 (4)
0056 Extra Length 0000 (0)
0058 Comment Length 0000 (0)
005A Disk Start 0000 (0)
005C Int File Attributes 0000 (0)
[Bit 0] 0 'Binary Data'
005E Ext File Attributes 81A40000 (2175008768)
[Bits 16-24] 01A4 (420) 'Unix attrib: rw-r--r--'
[Bits 28-31] 08 (8) 'Regular File'
0062 Local Header Offset 00000000 (0)
0066 Filename 'abc/'
#
# WARNING: Offset 0x66: Directory 'abc/' must not have a payload
#

006A END CENTRAL HEADER 06054B50 (101010256)
006E Number of this disk 0000 (0)
0070 Central Dir Disk no 0000 (0)
0072 Entries in this disk 0001 (1)
0074 Total Entries 0001 (1)
0076 Size of Central Dir 00000032 (50)
007A Offset to Central Dir 00000038 (56)
007E Comment Length 0000 (0)
#
# Warning Count: 2
#
# Done
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

0000 0003 0004 50 4B 03 04 LOCAL HEADER #1 04034B50 (67324752)
0004 0004 0001 14 Extract Zip Spec 14 (20) '2.0'
0005 0005 0001 00 Extract OS 00 (0) 'MS-DOS'
0006 0007 0002 08 00 General Purpose Flag 0008 (8)
[Bits 1-2] 0 'Normal Compression'
[Bit 3] 1 'Streamed'
0008 0009 0002 08 00 Compression Method 0008 (8) 'Deflated'
000A 000D 0004 7C 5B 9B 57 Last Mod Date/Time 579B5B7C (1469799292) 'Wed Dec 27 11:27:56 2023'
000E 0011 0004 00 00 00 00 CRC 00000000 (0)
0012 0015 0004 00 00 00 00 Compressed Size 00000000 (0)
0016 0019 0004 00 00 00 00 Uncompressed Size 00000000 (0)
001A 001B 0002 04 00 Filename Length 0004 (4)
001C 001D 0002 00 00 Extra Length 0000 (0)
001E 0021 0004 61 62 63 2F Filename 'abc/'
0022 0027 0006 4B 4C 4A 4E PAYLOAD KLJN..
01 00

0028 002B 0004 50 4B 07 08 DATA DESCRIPTOR 08074B50 (134695760)
002C 002F 0004 11 CD 82 ED CRC ED82CD11 (3984772369)
0030 0033 0004 06 00 00 00 Compressed Size 00000006 (6)
0034 0037 0004 04 00 00 00 Uncompressed Size 00000004 (4)
#
# WARNING: Directory 'abc/' must not have a payload
#

0038 003B 0004 50 4B 01 02 CENTRAL HEADER #1 02014B50 (33639248)
003C 003C 0001 14 Created Zip Spec 14 (20) '2.0'
003D 003D 0001 03 Created OS 03 (3) 'Unix'
003E 003E 0001 14 Extract Zip Spec 14 (20) '2.0'
003F 003F 0001 00 Extract OS 00 (0) 'MS-DOS'
0040 0041 0002 08 00 General Purpose Flag 0008 (8)
[Bits 1-2] 0 'Normal Compression'
[Bit 3] 1 'Streamed'
0042 0043 0002 08 00 Compression Method 0008 (8) 'Deflated'
0044 0047 0004 7C 5B 9B 57 Last Mod Date/Time 579B5B7C (1469799292) 'Wed Dec 27 11:27:56 2023'
0048 004B 0004 11 CD 82 ED CRC ED82CD11 (3984772369)
004C 004F 0004 06 00 00 00 Compressed Size 00000006 (6)
0050 0053 0004 04 00 00 00 Uncompressed Size 00000004 (4)
0054 0055 0002 04 00 Filename Length 0004 (4)
0056 0057 0002 00 00 Extra Length 0000 (0)
0058 0059 0002 00 00 Comment Length 0000 (0)
005A 005B 0002 00 00 Disk Start 0000 (0)
005C 005D 0002 00 00 Int File Attributes 0000 (0)
[Bit 0] 0 'Binary Data'
005E 0061 0004 00 00 A4 81 Ext File Attributes 81A40000 (2175008768)
[Bits 16-24] 01A4 (420) 'Unix attrib: rw-r--r--'
[Bits 28-31] 08 (8) 'Regular File'
0062 0065 0004 00 00 00 00 Local Header Offset 00000000 (0)
0066 0069 0004 61 62 63 2F Filename 'abc/'
#
# WARNING: Offset 0x66: Directory 'abc/' must not have a payload
#

006A 006D 0004 50 4B 05 06 END CENTRAL HEADER 06054B50 (101010256)
006E 006F 0002 00 00 Number of this disk 0000 (0)
0070 0071 0002 00 00 Central Dir Disk no 0000 (0)
0072 0073 0002 01 00 Entries in this disk 0001 (1)
0074 0075 0002 01 00 Total Entries 0001 (1)
0076 0079 0004 32 00 00 00 Size of Central Dir 00000032 (50)
007A 007D 0004 38 00 00 00 Offset to Central Dir 00000038 (56)
007E 007F 0002 00 00 Comment Length 0000 (0)
#
# Warning Count: 2
#
# Done
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
perl -MIO::Compress::Zip=:all -e 'zip \"abcd" => "test.zip", Minimal => 1, Stream => 0, Name => q[abc/]'
58 changes: 58 additions & 0 deletions t/files/0000-errors/badly-formed/directory-with-payload/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

0000 LOCAL HEADER #1 04034B50 (67324752)
0004 Extract Zip Spec 14 (20) '2.0'
0005 Extract OS 00 (0) 'MS-DOS'
0006 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
0008 Compression Method 0008 (8) 'Deflated'
000A Last Mod Date/Time 579B5A31 (1469798961) 'Wed Dec 27 11:17:34 2023'
000E CRC ED82CD11 (3984772369)
0012 Compressed Size 00000006 (6)
0016 Uncompressed Size 00000004 (4)
001A Filename Length 0004 (4)
001C Extra Length 0000 (0)
001E Filename 'abc/'
#
# WARNING: Offset 0x1E: Directory 'abc/' must not have a payload
#
0022 PAYLOAD KLJN..

0028 CENTRAL HEADER #1 02014B50 (33639248)
002C Created Zip Spec 14 (20) '2.0'
002D Created OS 03 (3) 'Unix'
002E Extract Zip Spec 14 (20) '2.0'
002F Extract OS 00 (0) 'MS-DOS'
0030 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
0032 Compression Method 0008 (8) 'Deflated'
0034 Last Mod Date/Time 579B5A31 (1469798961) 'Wed Dec 27 11:17:34 2023'
0038 CRC ED82CD11 (3984772369)
003C Compressed Size 00000006 (6)
0040 Uncompressed Size 00000004 (4)
0044 Filename Length 0004 (4)
0046 Extra Length 0000 (0)
0048 Comment Length 0000 (0)
004A Disk Start 0000 (0)
004C Int File Attributes 0000 (0)
[Bit 0] 0 'Binary Data'
004E Ext File Attributes 81A40000 (2175008768)
[Bits 16-24] 01A4 (420) 'Unix attrib: rw-r--r--'
[Bits 28-31] 08 (8) 'Regular File'
0052 Local Header Offset 00000000 (0)
0056 Filename 'abc/'
#
# WARNING: Offset 0x56: Directory 'abc/' must not have a payload
#

005A END CENTRAL HEADER 06054B50 (101010256)
005E Number of this disk 0000 (0)
0060 Central Dir Disk no 0000 (0)
0062 Entries in this disk 0001 (1)
0064 Total Entries 0001 (1)
0066 Size of Central Dir 00000032 (50)
006A Offset to Central Dir 00000028 (40)
006E Comment Length 0000 (0)
#
# Warning Count: 2
#
# Done
59 changes: 59 additions & 0 deletions t/files/0000-errors/badly-formed/directory-with-payload/stdout-v
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

0000 0003 0004 50 4B 03 04 LOCAL HEADER #1 04034B50 (67324752)
0004 0004 0001 14 Extract Zip Spec 14 (20) '2.0'
0005 0005 0001 00 Extract OS 00 (0) 'MS-DOS'
0006 0007 0002 00 00 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
0008 0009 0002 08 00 Compression Method 0008 (8) 'Deflated'
000A 000D 0004 31 5A 9B 57 Last Mod Date/Time 579B5A31 (1469798961) 'Wed Dec 27 11:17:34 2023'
000E 0011 0004 11 CD 82 ED CRC ED82CD11 (3984772369)
0012 0015 0004 06 00 00 00 Compressed Size 00000006 (6)
0016 0019 0004 04 00 00 00 Uncompressed Size 00000004 (4)
001A 001B 0002 04 00 Filename Length 0004 (4)
001C 001D 0002 00 00 Extra Length 0000 (0)
001E 0021 0004 61 62 63 2F Filename 'abc/'
#
# WARNING: Offset 0x1E: Directory 'abc/' must not have a payload
#
0022 0027 0006 4B 4C 4A 4E PAYLOAD KLJN..
01 00

0028 002B 0004 50 4B 01 02 CENTRAL HEADER #1 02014B50 (33639248)
002C 002C 0001 14 Created Zip Spec 14 (20) '2.0'
002D 002D 0001 03 Created OS 03 (3) 'Unix'
002E 002E 0001 14 Extract Zip Spec 14 (20) '2.0'
002F 002F 0001 00 Extract OS 00 (0) 'MS-DOS'
0030 0031 0002 00 00 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
0032 0033 0002 08 00 Compression Method 0008 (8) 'Deflated'
0034 0037 0004 31 5A 9B 57 Last Mod Date/Time 579B5A31 (1469798961) 'Wed Dec 27 11:17:34 2023'
0038 003B 0004 11 CD 82 ED CRC ED82CD11 (3984772369)
003C 003F 0004 06 00 00 00 Compressed Size 00000006 (6)
0040 0043 0004 04 00 00 00 Uncompressed Size 00000004 (4)
0044 0045 0002 04 00 Filename Length 0004 (4)
0046 0047 0002 00 00 Extra Length 0000 (0)
0048 0049 0002 00 00 Comment Length 0000 (0)
004A 004B 0002 00 00 Disk Start 0000 (0)
004C 004D 0002 00 00 Int File Attributes 0000 (0)
[Bit 0] 0 'Binary Data'
004E 0051 0004 00 00 A4 81 Ext File Attributes 81A40000 (2175008768)
[Bits 16-24] 01A4 (420) 'Unix attrib: rw-r--r--'
[Bits 28-31] 08 (8) 'Regular File'
0052 0055 0004 00 00 00 00 Local Header Offset 00000000 (0)
0056 0059 0004 61 62 63 2F Filename 'abc/'
#
# WARNING: Offset 0x56: Directory 'abc/' must not have a payload
#

005A 005D 0004 50 4B 05 06 END CENTRAL HEADER 06054B50 (101010256)
005E 005F 0002 00 00 Number of this disk 0000 (0)
0060 0061 0002 00 00 Central Dir Disk no 0000 (0)
0062 0063 0002 01 00 Entries in this disk 0001 (1)
0064 0065 0002 01 00 Total Entries 0001 (1)
0066 0069 0004 32 00 00 00 Size of Central Dir 00000032 (50)
006A 006D 0004 28 00 00 00 Offset to Central Dir 00000028 (40)
006E 006F 0002 00 00 Comment Length 0000 (0)
#
# Warning Count: 2
#
# Done
Binary file not shown.
2 changes: 2 additions & 0 deletions t/files/0000-errors/filenames/absolute-path/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

perl -MIO::Compress::Zip=:all -e 'zip \"abcd" => "test.zip", Minimal => 1, Stream => 0, Name => q[backslash\in\path]'
60 changes: 60 additions & 0 deletions t/files/0000-errors/filenames/absolute-path/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

0000 LOCAL HEADER #1 04034B50 (67324752)
0004 Extract Zip Spec 14 (20) '2.0'
0005 Extract OS 00 (0) 'MS-DOS'
0006 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
0008 Compression Method 0008 (8) 'Deflated'
000A Last Mod Date/Time 577A82C2 (1467646658) 'Sun Nov 26 16:22:04 2023'
000E CRC ED82CD11 (3984772369)
0012 Compressed Size 00000006 (6)
0016 Uncompressed Size 00000004 (4)
001A Filename Length 000E (14)
001C Extra Length 0000 (0)
001E Filename '/absolute/path'
#
# WARNING: Offset 0x1E: Filename '/absolute/path'
# Filename must not be an absolute path
#
002C PAYLOAD KLJN..

0032 CENTRAL HEADER #1 02014B50 (33639248)
0036 Created Zip Spec 14 (20) '2.0'
0037 Created OS 03 (3) 'Unix'
0038 Extract Zip Spec 14 (20) '2.0'
0039 Extract OS 00 (0) 'MS-DOS'
003A General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
003C Compression Method 0008 (8) 'Deflated'
003E Last Mod Date/Time 577A82C2 (1467646658) 'Sun Nov 26 16:22:04 2023'
0042 CRC ED82CD11 (3984772369)
0046 Compressed Size 00000006 (6)
004A Uncompressed Size 00000004 (4)
004E Filename Length 000E (14)
0050 Extra Length 0000 (0)
0052 Comment Length 0000 (0)
0054 Disk Start 0000 (0)
0056 Int File Attributes 0000 (0)
[Bit 0] 0 'Binary Data'
0058 Ext File Attributes 81A40000 (2175008768)
[Bits 16-24] 01A4 (420) 'Unix attrib: rw-r--r--'
[Bits 28-31] 08 (8) 'Regular File'
005C Local Header Offset 00000000 (0)
0060 Filename '/absolute/path'
#
# WARNING: Offset 0x60: Filename '/absolute/path'
# Filename must not be an absolute path
#

006E END CENTRAL HEADER 06054B50 (101010256)
0072 Number of this disk 0000 (0)
0074 Central Dir Disk no 0000 (0)
0076 Entries in this disk 0001 (1)
0078 Total Entries 0001 (1)
007A Size of Central Dir 0000003C (60)
007E Offset to Central Dir 00000032 (50)
0082 Comment Length 0000 (0)
#
# Warning Count: 2
#
# Done
67 changes: 67 additions & 0 deletions t/files/0000-errors/filenames/absolute-path/stdout-v
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

0000 0003 0004 50 4B 03 04 LOCAL HEADER #1 04034B50 (67324752)
0004 0004 0001 14 Extract Zip Spec 14 (20) '2.0'
0005 0005 0001 00 Extract OS 00 (0) 'MS-DOS'
0006 0007 0002 00 00 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
0008 0009 0002 08 00 Compression Method 0008 (8) 'Deflated'
000A 000D 0004 C2 82 7A 57 Last Mod Date/Time 577A82C2 (1467646658) 'Sun Nov 26 16:22:04 2023'
000E 0011 0004 11 CD 82 ED CRC ED82CD11 (3984772369)
0012 0015 0004 06 00 00 00 Compressed Size 00000006 (6)
0016 0019 0004 04 00 00 00 Uncompressed Size 00000004 (4)
001A 001B 0002 0E 00 Filename Length 000E (14)
001C 001D 0002 00 00 Extra Length 0000 (0)
001E 002B 000E 2F 61 62 73 Filename '/absolute/path'
6F 6C 75 74
65 2F 70 61
74 68
#
# WARNING: Offset 0x1E: Filename '/absolute/path'
# Filename must not be an absolute path
#
002C 0031 0006 4B 4C 4A 4E PAYLOAD KLJN..
01 00

0032 0035 0004 50 4B 01 02 CENTRAL HEADER #1 02014B50 (33639248)
0036 0036 0001 14 Created Zip Spec 14 (20) '2.0'
0037 0037 0001 03 Created OS 03 (3) 'Unix'
0038 0038 0001 14 Extract Zip Spec 14 (20) '2.0'
0039 0039 0001 00 Extract OS 00 (0) 'MS-DOS'
003A 003B 0002 00 00 General Purpose Flag 0000 (0)
[Bits 1-2] 0 'Normal Compression'
003C 003D 0002 08 00 Compression Method 0008 (8) 'Deflated'
003E 0041 0004 C2 82 7A 57 Last Mod Date/Time 577A82C2 (1467646658) 'Sun Nov 26 16:22:04 2023'
0042 0045 0004 11 CD 82 ED CRC ED82CD11 (3984772369)
0046 0049 0004 06 00 00 00 Compressed Size 00000006 (6)
004A 004D 0004 04 00 00 00 Uncompressed Size 00000004 (4)
004E 004F 0002 0E 00 Filename Length 000E (14)
0050 0051 0002 00 00 Extra Length 0000 (0)
0052 0053 0002 00 00 Comment Length 0000 (0)
0054 0055 0002 00 00 Disk Start 0000 (0)
0056 0057 0002 00 00 Int File Attributes 0000 (0)
[Bit 0] 0 'Binary Data'
0058 005B 0004 00 00 A4 81 Ext File Attributes 81A40000 (2175008768)
[Bits 16-24] 01A4 (420) 'Unix attrib: rw-r--r--'
[Bits 28-31] 08 (8) 'Regular File'
005C 005F 0004 00 00 00 00 Local Header Offset 00000000 (0)
0060 006D 000E 2F 61 62 73 Filename '/absolute/path'
6F 6C 75 74
65 2F 70 61
74 68
#
# WARNING: Offset 0x60: Filename '/absolute/path'
# Filename must not be an absolute path
#

006E 0071 0004 50 4B 05 06 END CENTRAL HEADER 06054B50 (101010256)
0072 0073 0002 00 00 Number of this disk 0000 (0)
0074 0075 0002 00 00 Central Dir Disk no 0000 (0)
0076 0077 0002 01 00 Entries in this disk 0001 (1)
0078 0079 0002 01 00 Total Entries 0001 (1)
007A 007D 0004 3C 00 00 00 Size of Central Dir 0000003C (60)
007E 0081 0004 32 00 00 00 Offset to Central Dir 00000032 (50)
0082 0083 0002 00 00 Comment Length 0000 (0)
#
# Warning Count: 2
#
# Done
Binary file added t/files/0000-errors/filenames/absolute-path/test.zip
Binary file not shown.
Loading

0 comments on commit 49735a7

Please sign in to comment.