A member’s name is a run of bytes with its length held separately, in both the local and central headers. There is no NUL at the end. This page covers what those bytes may be and how to decode them.
Paths and separators
- A name may include a relative path. Its folders are separated by forward slashes
(
/). Backslashes are not separators in the format. - A name must not start with a slash, and must not include a drive or device letter.
- A name’s length is limited by its 16-bit field, to 65,535 bytes. APPNOTE says the name, extra field and comment together should not generally exceed that.
- If the file came from standard input, APPNOTE says it has no name field.
- With an encrypted central directory and bit 13 set, the local header holds a sequential hexadecimal number instead of the name.
In practice, archives made on Windows sometimes contain backslashes, and a reader
may need to convert them. The explorer treats a trailing backslash as a folder as well
as a trailing slash. Names can contain .. and absolute paths in malicious
archives; see path traversal.
Folders
A folder is usually an entry whose name ends with a slash, with no data: the method is 0 and both sizes are zero. APPNOTE sets the version needed for a folder at 2.0. It says that entries with no content must not include file data, but does not itself state the trailing slash convention.
The attributes can also mark a folder, with the 0x10 DOS bit or a Unix
mode whose type is 040000: see
external attributes. A reader should
accept a trailing slash, and many extractors create folders from file paths anyway,
since not all archives list them.
Encodings
There are two encodings, and flag bit 11 says which:
| Bit 11 | Encoding of the name and comment |
|---|---|
| Clear | The original encoding, IBM code page 437. |
| Set | UTF-8 (Unicode 4.1.0 or later), with no byte order mark. |
Bit 11 covers only the name and member comment. It says nothing about file contents or passwords. Bytes 32 to 126 are ASCII in both encodings, so a name in plain ASCII reads the same either way. Only names with bytes over 127 are affected.
Many tools did not follow the rule. Some wrote UTF-8 names with bit 11 clear, including macOS Archive Utility and older versions of Java, and others have used the system’s own code page. So a reader often cannot trust a clear bit 11. The explorer, like Info-ZIP and libarchive, reads a non-ASCII name without the bit as UTF-8 if it is valid UTF-8, and as code page 437 otherwise.
Unicode extra fields
A writer can keep an old encoding in the name field, for older readers, and put the real name in UTF-8 in a 0x7075 Unicode path block. A similar 0x6375 Unicode comment block does the same for comments. These keep archives readable by old tools, at the cost of space, unlike bit 11, which takes no extra space but old programs may not understand.
The block holds the CRC-32 of the header’s name, so a reader can tell that the block still applies. If a tool renames a member without knowing about the block, the CRC-32 no longer matches and the block must be ignored.
Comments