Skip to content

Commit a293883

Browse files
armijnhemelfolkertdev
authored andcommitted
add test file for files with absolute file names (which are not allowed
according to the specifications)
1 parent d1017c6 commit a293883

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

testdata/absolute-name.zip

134 Bytes
Binary file not shown.

testdata/readme.absolutefilename

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
The use of absolute paths in file names is not allowed according to the
2+
specifications (section 4.4.17):
3+
4+
```
5+
The path stored MUST NOT contain a drive or
6+
device letter, or a leading slash.
7+
```
8+
9+
In `unzip` it is not possible to create a file with absolute paths, but
10+
creating a file with a leading slash (or even multiple) is absolutely no
11+
problem using Python's `zipfile` module:
12+
13+
```
14+
>>> import zipfile
15+
>>> z = zipfile.ZipInfo('/tmp/absolute')
16+
>>> contents = 10*b'c'
17+
>>> bla = zipfile.ZipFile('/tmp/absolute-name.zip', mode='w')
18+
>>> bla.writestr(z, contents)
19+
>>> bla.close()
20+
```
21+
22+
`unzip` will unpack this to a relative path but also issue a warning:
23+
24+
```
25+
$ unzip /tmp/bla.zip
26+
Archive: /tmp/bla.zip
27+
warning: stripped absolute path spec from /tmp/absolute
28+
extracting: tmp/absolute
29+
```
30+
31+
`p7zip` will also correctly unpack the file, but not issue a warning:
32+
33+
```
34+
$ 7z x /tmp/bla.zip
35+
36+
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
37+
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,8 CPUs Intel(R) Core(TM) i7-6770HQ CPU @ 2.60GHz (506E3),ASM,AES-NI)
38+
39+
Scanning the drive for archives:
40+
1 file, 134 bytes (1 KiB)
41+
42+
Extracting archive: /tmp/bla.zip
43+
--
44+
Path = /tmp/bla.zip
45+
Type = zip
46+
Physical Size = 134
47+
48+
Everything is Ok
49+
50+
Size: 10
51+
Compressed: 134
52+
```
53+
54+
Python's `zipfile` will also correctly unpack the file, but issue no warning.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
source: ziplinter/src/lib.rs
3+
expression: result
4+
---
5+
{
6+
"comment": "",
7+
"contents": [
8+
{
9+
"central": {
10+
"comment": "",
11+
"compressed_size": 10,
12+
"crc32": 4044738111,
13+
"creator_version": {
14+
"host_system": "Unix",
15+
"version": 20
16+
},
17+
"disk_nbr_start": 0,
18+
"external_attrs": 25165824,
19+
"extra": [],
20+
"flags": 0,
21+
"header_offset": 0,
22+
"internal_attrs": 0,
23+
"method": "Store",
24+
"mode": 384,
25+
"modified": "1980-01-01T00:00:00Z",
26+
"name": "/tmp/absolute",
27+
"reader_version": {
28+
"host_system": "MsDos",
29+
"version": 20
30+
},
31+
"uncompressed_size": 10
32+
},
33+
"local": {
34+
"accessed": null,
35+
"compressed_size": 10,
36+
"crc32": 4044738111,
37+
"created": null,
38+
"extra": [],
39+
"flags": 0,
40+
"gid": null,
41+
"header_offset": 0,
42+
"method": "Store",
43+
"method_specific": "None",
44+
"mode": 0,
45+
"modified": "1980-01-01T00:00:00Z",
46+
"name": "/tmp/absolute",
47+
"reader_version": {
48+
"host_system": "MsDos",
49+
"version": 20
50+
},
51+
"uid": null,
52+
"uncompressed_size": 10
53+
}
54+
}
55+
],
56+
"encoding": "Utf8",
57+
"eocd": {
58+
"dir": {
59+
"inner": {
60+
"dir_disk_nbr": 0,
61+
"dir_records_this_disk": 1,
62+
"directory_offset": 53,
63+
"directory_records": 1,
64+
"directory_size": 59,
65+
"disk_nbr": 0
66+
},
67+
"offset": 112
68+
},
69+
"dir64": null,
70+
"global_offset": 0
71+
},
72+
"parsed_ranges": [
73+
{
74+
"contains": "end of central directory record",
75+
"end": 134,
76+
"start": 112
77+
},
78+
{
79+
"contains": "central directory header",
80+
"end": 112,
81+
"filename": "/tmp/absolute",
82+
"start": 53
83+
},
84+
{
85+
"contains": "local file header",
86+
"end": 43,
87+
"filename": "/tmp/absolute",
88+
"start": 0
89+
},
90+
{
91+
"contains": "file data",
92+
"end": 53,
93+
"filename": "/tmp/absolute",
94+
"start": 43
95+
}
96+
],
97+
"size": 134
98+
}

0 commit comments

Comments
 (0)