From b82756da9ec3df65a2e3e5f918b05916c917233f Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Mon, 22 Dec 2025 19:53:41 +0100 Subject: [PATCH] add test file for files with absolute file names (which are not allowed according to the specifications) --- testdata/absolute-name.zip | Bin 0 -> 134 bytes testdata/readme.absolutefilename | 54 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 testdata/absolute-name.zip create mode 100644 testdata/readme.absolutefilename diff --git a/testdata/absolute-name.zip b/testdata/absolute-name.zip new file mode 100644 index 0000000000000000000000000000000000000000..4fa5b822258878244a5b8a8cca5fdb651554447e GIT binary patch literal 134 zcmWIWW@Zs#fB;1X`*WfnxquuH<^^K?lH3CQ#H8Z>> 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.