Skip to content

Wrong value in general purpose bit flag #4

@marhop

Description

@marhop

Problem Description

I zipped a non-empty text file with the zip64 command line tool. When I unzipped it with another tool (UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.), the extracted text file was empty. The same problem occurs with files created by SIARD Suite, so this is not limited to the command line tool but the bug lurks somewhere in the library.

Analysis

(See example file below.)

I think there is a problem with the general purpose bit flag in the local file header and in the central directory file header. If I am not mistaken (which may be the case because little endian byte order makes my head hurt), 0408 resolves to 0x0804 = 0000100000000100, so bits 2 and 11 are set. (Counting starts at 0.) According to [APPNOTE section 4.4.4] bit 2 is relevant only for a specific compression type that's not used here, so it counts as undefined.

Maybe it was intended to set bit 3 (0x0808) instead of 2, announcing the data descriptor that follows down below? (Bit 11 denotes UTF-8 file names and comments, so that's OK.)

If bit 3 is set instead of bit 2 the zipped file is extracted correctly.

Example File

This is the hex representation of a ZIP file created with Zip64File 2.0.60 (looks the same with 2.1.34) using the following command where hello.txt contains the string "hello world":

$ zip64 n a.zip hello.txt

If you'd like to play with the hex data (like changing the general purpose bit flags), a binary ZIP file can be compiled from it using this tool.

Local File Header

Note the general purpose bit flag!

504b 0304              # local file header signature
2d00                   # version needed to extract
0408                   # general purpose bit flag → change to 0808!
0000                   # compression method
a97e                   # last mod file time
264d                   # last mod file date
0000 0000              # crc-32
ffff ffff              # compressed size
ffff ffff              # uncompressed size
0900                   # file name length
1400                   # extra field length
6865 6c6c 6f2e 7478 74 # file name "hello.txt"

0100                   # header ID "Zip64 extended information extra field"
1000                   # data size
0000 0000 0000 0000    # uncompressed size
0000 0000 0000 0000    # compressed size

File Data

ASCII string "hello world", uncompressed. This looks fine.

6865 6c6c 6f20 776f 726c 640a

Data Descriptor

Looks OK.

504b 0708              # data descriptor signature
2d3b 08af              # crc-32
0c00 0000 0000 0000    # compressed size
0c00 0000 0000 0000    # uncompressed size

Central Directory Header

Note the general purpose bit flag!

504b 0102              # central file header signature
2d00                   # version made by
2d00                   # version needed to extract
0408                   # general purpose bit flag → change to 0808!
0000                   # compression method
a97e                   # last mod file time
264d                   # last mod file date
2d3b 08af              # crc-32
0c00 0000              # compressed size
0c00 0000              # uncompressed size
0900                   # file name length
0000                   # extra field length
0000                   # file comment length
0000                   # disk number start
0000                   # internal file attributes
0000 0000              # external file attributes
0000 0000              # relative offset of local header
6865 6c6c 6f2e 7478 74 # file name "hello.txt"

End Of Central Directory Record

Looks OK.

504b 0506              # end of central directory signature
0000                   # number of this disk
0000                   # number of the disk with start of central directory
0100                   # number of entries in central directory on this disk
0100                   # number of entries in central directory
3700 0000              # size of central directory
5f00 0000              # offset of start of central directory
0000                   # ZIP file comment length

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions