diff --git a/testdata/absolute-name.zip b/testdata/absolute-name.zip new file mode 100644 index 0000000..4fa5b82 Binary files /dev/null and b/testdata/absolute-name.zip differ diff --git a/testdata/readme.absolutefilename b/testdata/readme.absolutefilename new file mode 100644 index 0000000..01704ff --- /dev/null +++ b/testdata/readme.absolutefilename @@ -0,0 +1,54 @@ +The use of absolute paths in file names is not allowed according to the +specifications (section 4.4.17): + +``` +The path stored MUST NOT contain a drive or +device letter, or a leading slash. +``` + +In `unzip` it is not possible to create a file with absolute paths, but +creating a file with a leading slash (or even multiple) is absolutely no +problem using Python's `zipfile` module: + +``` +>>> import zipfile +>>> z = zipfile.ZipInfo('/tmp/absolute') +>>> contents = 10*b'c' +>>> bla = zipfile.ZipFile('/tmp/absolute-name.zip', mode='w') +>>> bla.writestr(z, contents) +>>> bla.close() +``` + +`unzip` will unpack this to a relative path but also issue a warning: + +``` +$ unzip /tmp/bla.zip +Archive: /tmp/bla.zip +warning: stripped absolute path spec from /tmp/absolute + extracting: tmp/absolute +``` + +`p7zip` will also correctly unpack the file, but not issue a warning: + +``` +$ 7z x /tmp/bla.zip + +7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21 +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) + +Scanning the drive for archives: +1 file, 134 bytes (1 KiB) + +Extracting archive: /tmp/bla.zip +-- +Path = /tmp/bla.zip +Type = zip +Physical Size = 134 + +Everything is Ok + +Size: 10 +Compressed: 134 +``` + +Python's `zipfile` will also correctly unpack the file, but issue no warning. diff --git a/ziplinter/src/snapshots/ziplinter__test__absolute-name.zip.snap b/ziplinter/src/snapshots/ziplinter__test__absolute-name.zip.snap new file mode 100644 index 0000000..b8e2b73 --- /dev/null +++ b/ziplinter/src/snapshots/ziplinter__test__absolute-name.zip.snap @@ -0,0 +1,98 @@ +--- +source: ziplinter/src/lib.rs +expression: result +--- +{ + "comment": "", + "contents": [ + { + "central": { + "comment": "", + "compressed_size": 10, + "crc32": 4044738111, + "creator_version": { + "host_system": "Unix", + "version": 20 + }, + "disk_nbr_start": 0, + "external_attrs": 25165824, + "extra": [], + "flags": 0, + "header_offset": 0, + "internal_attrs": 0, + "method": "Store", + "mode": 384, + "modified": "1980-01-01T00:00:00Z", + "name": "/tmp/absolute", + "reader_version": { + "host_system": "MsDos", + "version": 20 + }, + "uncompressed_size": 10 + }, + "local": { + "accessed": null, + "compressed_size": 10, + "crc32": 4044738111, + "created": null, + "extra": [], + "flags": 0, + "gid": null, + "header_offset": 0, + "method": "Store", + "method_specific": "None", + "mode": 0, + "modified": "1980-01-01T00:00:00Z", + "name": "/tmp/absolute", + "reader_version": { + "host_system": "MsDos", + "version": 20 + }, + "uid": null, + "uncompressed_size": 10 + } + } + ], + "encoding": "Utf8", + "eocd": { + "dir": { + "inner": { + "dir_disk_nbr": 0, + "dir_records_this_disk": 1, + "directory_offset": 53, + "directory_records": 1, + "directory_size": 59, + "disk_nbr": 0 + }, + "offset": 112 + }, + "dir64": null, + "global_offset": 0 + }, + "parsed_ranges": [ + { + "contains": "end of central directory record", + "end": 134, + "start": 112 + }, + { + "contains": "central directory header", + "end": 112, + "filename": "/tmp/absolute", + "start": 53 + }, + { + "contains": "local file header", + "end": 43, + "filename": "/tmp/absolute", + "start": 0 + }, + { + "contains": "file data", + "end": 53, + "filename": "/tmp/absolute", + "start": 43 + } + ], + "size": 134 +}