Skip to content

[Bug] - file doesn't recognize zip some files if piped in via stdin #1055

@jcoetzee

Description

@jcoetzee

Describe the bug
The version of file/libmagic in AL2023 fails to classify certain zip files that are piped in via stdin while the same zip files are classified correctly on AL2.

To Reproduce
The easiest way to produce a zip file that isn't classified correctly is through python's zipfile (I haven't had success trying to create a toy example with zip).

import zipfile

with zipfile.ZipFile('test.zip', 'w', zipfile.ZIP_DEFLATED) as zipf:
    zipf.writestr("test.txt", "test content")

AL2023:

sh-5.2$ file test.zip
test.zip: Zip archive data, made by v2.0 UNIX, extract using at least v2.0, last modified Thu Jan 10 09:46:46 2019, uncompressed size 12, method=deflate
sh-5.2$ cat test.zip | file -
/dev/stdin: data

AL2:

sh-4.2$ file test.zip
test.zip: Zip archive data, at least v2.0 to extract
sh-4.2$ cat test.zip | file -
/dev/stdin: Zip archive data, at least v2.0 to extract

Files created via zip are classified correctly however (most likely because of the lack of metadata that python adds by default)

$ dd if=/dev/urandom of=randomfile.bin bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0333076 s, 315 MB/s
$ zip test2.zip randomfile.bin
  adding: randomfile.bin (deflated 0%)
$ file test2.zip
test2.zip: Zip archive data, at least v2.0 to extract
$ cat test2.zip | file -
/dev/stdin: Zip archive data, at least v2.0 to extract

Expected behavior
The zip file should be classified correctly regardless of whether passed in as a file or piped via stdin (at least for small zip files)

Additional context

sh-5.2$ file --version
file-5.39
magic file from /etc/magic:/usr/share/misc/magic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions