npm @zip.js/zip.js 2.19.0

latest releases: 2.25.0, 2.24.0, 2.23.0...
one month ago

What's Changed in v2.19.0

Bug fixes

  • A Unicode Path extra field (0x7075) no longer bypasses filenameValidation: the name of a valid field replaced the decoded central directory name after that name had been validated, so an entry named safe.txt in its record and ../evil.txt in the field was listed as ../evil.txt at the "strict" and "balanced" levels. The validation and normalizeFilename now run on the final name, so such an entry fails getEntries() with ERR_UNSAFE_FILENAME carrying the name of the field, normalizeFilename receives that name and can repair it, and "tolerant" still keeps it. Conversely, an unsafe record name overridden by a safe field is now accepted, since the name reported is the safe one; rawFilename still holds the bytes of the record
  • With unixExtraFieldType: "unix", the Info-ZIP Unix type 2 extra field (0x7855) is written as Info-ZIP's zip writes it and its extrafld.txt specifies: the 2-byte uid and gid in the local file header, and the tag with a size of 0 in the central directory record, where the 4 bytes used to be repeated. As for the archives Info-ZIP writes, entry.uid and entry.gid of such an entry are undefined after getEntries() and filled in once the entry data has been read: code reading them right after getEntries() on an archive written this way by 2.19.0 has to read the data first, or read entry.localDirectory.uid after getData(), or write the entries with the default "infozip" type. Archives written with "unix" by earlier versions keep reporting the ids at getEntries(), since their central directory copy holds them
  • ZipFS exports keep re-emitting imported ids as a New Unix extra field (0x7875), which stores them in both records, unless unixExtraFieldType is set on the export
  • When a record carries both a New Unix extra field (0x7875) and a type 2 field (0x7855) holding ids, the ids come from the New Unix field, to which Info-ZIP gives precedence and which is not limited to 16 bits; the type 2 ids used to win, so a uid of 70000 next to its truncated 4464 was reported as 4464. extraFieldUnix.uid and extraFieldUnix.gid still report the type 2 values
  • ZipWriter#add() no longer accesses the readable getter of a reader that implements readUint8Array(), e.g. a BlobReader, a Uint8ArrayReader or an HttpRangeReader: the check for a usable reader read readable first, which on these classes creates a new stream on each access, and that stream pulled its first chunk before being discarded, one wasted range request per add() for a remote reader

Behaviour changes

  • The default chunkSize is 256 KiB instead of 64 KiB. Every stage of the pipeline of an entry holds up to one chunk and the data crosses the boundary of a web worker one chunk per message, so the change buys fewer messages for more memory per entry in progress. Where it shows: concurrent add() on Bun 1.4.2 takes 0.24 s instead of 1.20 s, since its native CompressionStream leaves the JavaScript thread only for writes larger than 128 KB, and the worker paths gain in proportion to the number of messages saved. What it costs, measured in isolation on Node.js in-process: about 20 MB more peak memory on a 256 MB stream and on a 20 MB text entry. Applications on memory-tight targets, e.g. browser extensions or mobile pages with many entries in flight, can keep the previous value with configure({ chunkSize: 64 * 1024 }). BENCHMARKS.md was re-run on the new default
  • The streams of an entry are never transferred to a web worker any more: the data always crosses the boundary chunk by chunk, which was never slower and is faster in the browsers, measured with a warmed worker on a 32 MiB deflated entry: Safari 27 reads in 38 ms against 80 with the transfer and writes in 93 against 156, Firefox 156 reads in 75 to 80 ms against 86 to 89 and writes in 32 to 36 against 79 to 87, Chrome 153 writes in 69 against 85 and reads in the same time, Deno is on par, and Bun does not support transferable streams. The transferStreams option of configure() and of the per-call options is accepted and ignored, and deprecated in the type declarations; an application that set transferStreams: false to work around a failure has nothing to change and can drop the option

Documentation

  • GetEntriesOptions#filenameValidation and GetEntriesOptions#normalizeFilename state that the name validated and normalized is the final one, after a valid Unicode Path extra field has replaced it; extraFieldUnix and extraFieldInfoZip of EntryMetaData and of LocalDirectory, and EntryMetaData#localDirectory, describe which field the ids come from and when the local file header fills them in; ZipWriterConstructorOptions#unixExtraFieldType says where the "unix" ids are stored and when a reader sees them; Configuration#chunkSize gains a remark on its memory and message cost; Reader#readable says it returns a new stream reading from the start on each access; WorkerConfiguration#transferStreams is marked deprecated
  • The tests README and two test comments no longer describe streams being transferred to the worker

Tests and continuous integration

  • The filename validation test builds an entry whose Unicode Path extra field escapes the directory and checks it at every level and through normalizeFilename; the Unix extra field layout test pins the empty central directory copy of the type 2 field and reads the ids after the data; the local header ids test adds a record carrying both Unix fields with ids and a central directory carrying only the New Unix field while the local file header carries only the type 2 one; a new test counts the reads a reader receives from add()

Benchmarks

  • QUICK=1 runs the benchmark scripts on a reduced matrix in about 50 seconds, for a smoke check of the harness rather than for the page; bench-crc.js follows the current options of the deflate stream

Full Changelog: v2.18.2...v2.19.0

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

Don't miss a new zip.js release

NewReleases is sending notifications on new releases.