From 39a1dc14320b3b5a881255dd3ae82866c60d9c5e Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Sun, 18 Feb 2024 13:02:14 -0500 Subject: [PATCH] fix handling of explicitly null options --- README.md | 1 + index.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18f0bd0..009181b 100644 --- a/README.md +++ b/README.md @@ -763,6 +763,7 @@ This library makes no attempt to interpret the Language Encoding Flag. Added fields to `Class: Entry`: `fileNameRaw`, `extraFieldRaw`, `fileCommentRaw`. * Added `examples/compareCentralAndLocalHeaders.js` that demonstrate many of these low level APIs. * Noted dropped support of node versions before 12 in the `"engines"` field of `package.json`. + * Fixed a crash when calling `openReadStream()` with an explicitly `null` options parameter (as opposed to omitted). * 3.0.0 * BREAKING CHANGE: implementations of [RandomAccessReader](#class-randomaccessreader) that implement a `destroy` method must instead implement `_destroy` in accordance with the node standard https://nodejs.org/api/stream.html#writable_destroyerr-callback (note the error and callback parameters). If you continue to override `destory` instead, some error handling may be subtly broken. Additionally, this is required for async iterators to work correctly in some versions of node. [issue #110](https://github.com/thejoshwolfe/yauzl/issues/110) * BREAKING CHANGE: Drop support for node versions older than 12. diff --git a/index.js b/index.js index d220244..b09fd90 100644 --- a/index.js +++ b/index.js @@ -402,6 +402,9 @@ ZipFile.prototype.openReadStream = function(entry, options, callback) { var relativeEnd = entry.compressedSize; if (callback == null) { callback = options; + options = null; + } + if (options == null) { options = {}; } else { // validate options that the caller has no excuse to get wrong @@ -519,8 +522,9 @@ ZipFile.prototype.readLocalFileHeader = function(entry, options, callback) { var self = this; if (callback == null) { callback = options; - options = {}; + options = null; } + if (options == null) options = {}; self.reader.ref(); var buffer = newBuffer(30); @@ -754,6 +758,7 @@ RandomAccessReader.prototype.unref = function() { } }; RandomAccessReader.prototype.createReadStream = function(options) { + if (options == null) options = {}; var start = options.start; var end = options.end; if (start === end) {