Skip to content

Entries are written with invalid MS-DOS date 0x0000 ("1980-00-00") #3

Open

Description

@trackoor

toBuffer() writes 0 (0x0000) into the last-mod date fields of both the local file header and the central directory header, which encodes month 0 and day 0 (1980-00-00) instead of a valid MS-DOS date.

// repro.mjs (npm i @aklinker1/zero-zip@1.0.1)
import { writeFile } from "node:fs/promises";
import { createZip } from "@aklinker1/zero-zip";

const zip = createZip();
zip.addFile("hello.txt", "Hello, world!");
await writeFile("example.zip", await zip.toBuffer());

Run node repro.mjs and inspect example.zip:

$ unzip -l example.zip
Archive:  example.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
       13  1980-00-00 00:00   hello.txt
---------                     -------
       13                     1 file

$ python3 -c 'import zipfile, datetime; i = zipfile.ZipFile("example.zip").infolist()[0]; print(i.date_time); datetime.datetime(*i.date_time)'
(1980, 0, 0, 0, 0, 0)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: month must be in 1..12

$ unzip -q example.zip -d out && stat -c "%y %n" out/hello.txt
1979-12-31 00:00:00.000000000 +0000 out/hello.txt

$ python3 -c 'import shutil; shutil.make_archive("rezip", "zip", "out")'
Traceback (most recent call last):
  ...
ValueError: ZIP does not support timestamps before 1980

7z l leaves the date column blank, and yauzl, jszip, Go archive/zip, and jar decode the timestamp as 1979-11-30. Expected: a valid MS-DOS date (APPNOTE.TXT 4.4.6, where month is 1-12 and day is 1-31), such as the current date/time or 0x0021 (1980-01-01) as a fixed default.

In index.ts, w16(localHeader, 0, 12) and w16(centralHeader, 0, 14) write 0 for the date field (0 is valid for MS-DOS time 00:00:00, whereas the minimum valid MS-DOS date is (1 << 5) | 1 = 0x0021).

Tested on @aklinker1/zero-zip@1.0.1 (npm and JSR) and main (b15b883) with Node.js v26.13.0 on Linux.

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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