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 namedsafe.txtin its record and../evil.txtin the field was listed as../evil.txtat the"strict"and"balanced"levels. The validation andnormalizeFilenamenow run on the final name, so such an entry failsgetEntries()withERR_UNSAFE_FILENAMEcarrying the name of the field,normalizeFilenamereceives 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;rawFilenamestill holds the bytes of the record - With
unixExtraFieldType: "unix", the Info-ZIP Unix type 2 extra field (0x7855) is written as Info-ZIP'szipwrites it and itsextrafld.txtspecifies: 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.uidandentry.gidof such an entry areundefinedaftergetEntries()and filled in once the entry data has been read: code reading them right aftergetEntries()on an archive written this way by 2.19.0 has to read the data first, or readentry.localDirectory.uidaftergetData(), or write the entries with the default"infozip"type. Archives written with"unix"by earlier versions keep reporting the ids atgetEntries(), since their central directory copy holds them ZipFSexports keep re-emitting imported ids as a New Unix extra field (0x7875), which stores them in both records, unlessunixExtraFieldTypeis 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.uidandextraFieldUnix.gidstill report the type 2 values ZipWriter#add()no longer accesses thereadablegetter of a reader that implementsreadUint8Array(), e.g. aBlobReader, aUint8ArrayReaderor anHttpRangeReader: the check for a usable reader readreadablefirst, 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 peradd()for a remote reader
Behaviour changes
- The default
chunkSizeis 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: concurrentadd()on Bun 1.4.2 takes 0.24 s instead of 1.20 s, since its nativeCompressionStreamleaves 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 withconfigure({ 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
transferStreamsoption ofconfigure()and of the per-call options is accepted and ignored, and deprecated in the type declarations; an application that settransferStreams: falseto work around a failure has nothing to change and can drop the option
Documentation
GetEntriesOptions#filenameValidationandGetEntriesOptions#normalizeFilenamestate that the name validated and normalized is the final one, after a valid Unicode Path extra field has replaced it;extraFieldUnixandextraFieldInfoZipofEntryMetaDataand ofLocalDirectory, andEntryMetaData#localDirectory, describe which field the ids come from and when the local file header fills them in;ZipWriterConstructorOptions#unixExtraFieldTypesays where the"unix"ids are stored and when a reader sees them;Configuration#chunkSizegains a remark on its memory and message cost;Reader#readablesays it returns a new stream reading from the start on each access;WorkerConfiguration#transferStreamsis 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 fromadd()
Benchmarks
QUICK=1runs 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.jsfollows 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