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

Open Beginner friendly
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
nodejs, typescript
Domain
devtools

Research direction

The bad date is written in index.ts at the two w16 calls, w16(localHeader, 0, 12) and w16(centralHeader, 0, 14), which set the last-mod date field to 0. Read the surrounding header-building code to see how the time and date fields are laid out, then run the repro script and inspect the output with unzip -l or Python's zipfile. Done when the date reads as a valid MS-DOS date (such as 1980-01-01, or the current date) in both headers and the Python zipfile check no longer raises.

Written by the indexing model from the issue text.

Description

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/[email protected])
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/[email protected] (npm and JSR) and main (b15b883) with Node.js v26.13.0 on Linux.

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

Dominant language
TypeScript
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.