From bd83f197f4a376f3996706d6522588f025b2fc32 Mon Sep 17 00:00:00 2001 From: Iacob Nasca Date: Thu, 14 Mar 2024 08:49:38 +0200 Subject: [PATCH] Fixed extraction bug --- headers/entryHeader.js | 59 ++++++++++++++---------------------------- package-lock.json | 16 ++++++------ package.json | 2 +- zipEntry.js | 3 +-- 4 files changed, 29 insertions(+), 51 deletions(-) diff --git a/headers/entryHeader.js b/headers/entryHeader.js index a32def1..051d389 100644 --- a/headers/entryHeader.js +++ b/headers/entryHeader.js @@ -170,60 +170,39 @@ module.exports = function () { }, get realDataOffset() { - return _offset + Constants.LOCHDR + _fnameLen + _extraLen; + return _offset + Constants.LOCHDR + _dataHeader.fnameLen + _dataHeader.extraLen; }, get dataHeader() { + return _dataHeader; + }, + + loadDataHeaderFromBinary: function (/*Buffer*/ input) { + var data = input.slice(_offset, _offset + Constants.LOCHDR); + // 30 bytes and should start with "PK\003\004" + if (data.readUInt32LE(0) !== Constants.LOCSIG) { + throw new Error(Utils.Errors.INVALID_LOC); + } _dataHeader = { // version needed to extract - version: _version, + version: data.readUInt16LE(Constants.LOCVER), // general purpose bit flag - flags: _flags, + flags: data.readUInt16LE(Constants.LOCFLG), // compression method - method: _method, + method: data.readUInt16LE(Constants.LOCHOW), // modification time (2 bytes time, 2 bytes date) - time: _time, + time: data.readUInt32LE(Constants.LOCTIM), // uncompressed file crc-32 value - crc: _crc, + crc: data.readUInt32LE(Constants.LOCCRC), // compressed size - compressedSize: _compressedSize, + compressedSize: data.readUInt32LE(Constants.LOCSIZ), // uncompressed size - size: _size, + size: data.readUInt32LE(Constants.LOCLEN), // filename length - fnameLen: _fnameLen, + fnameLen: data.readUInt16LE(Constants.LOCNAM), // extra field length - extraLen: _extraLen + extraLen: data.readUInt16LE(Constants.LOCEXT) }; - - return _dataHeader; - }, - - loadDataHeaderFromBinary: function (/*Buffer*/ input) { - var data = input.slice(_offset, _offset + Constants.LOCHDR); - // 30 bytes and should start with "PK\003\004" - if (data.readUInt32LE(0) !== Constants.LOCSIG) { - throw new Error(Utils.Errors.INVALID_LOC); - } - - // version needed to extract - _version = data.readUInt16LE(Constants.LOCVER); - // general purpose bit flag - _flags = data.readUInt16LE(Constants.LOCFLG); - // compression method - _method = data.readUInt16LE(Constants.LOCHOW); - // modification time (2 bytes time, 2 bytes date) - _time = data.readUInt32LE(Constants.LOCTIM); - // uncompressed file crc-32 value - _crc = data.readUInt32LE(Constants.LOCCRC); - // compressed size - _compressedSize = data.readUInt32LE(Constants.LOCSIZ); - // uncompressed size - _size = data.readUInt32LE(Constants.LOCLEN); - // filename length - _fnameLen = data.readUInt16LE(Constants.LOCNAM); - // extra field length - _extraLen = data.readUInt16LE(Constants.LOCEXT); - }, loadFromBinary: function (/*Buffer*/ data) { diff --git a/package-lock.json b/package-lock.json index a9171c2..feb10c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "adm-zip", - "version": "0.5.9", + "version": "0.5.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "adm-zip", - "version": "0.5.9", + "version": "0.5.11", "license": "MIT", "devDependencies": { "chai": "^4.3.4", @@ -435,9 +435,9 @@ } }, "node_modules/get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", "dev": true, "engines": { "node": "*" @@ -1413,9 +1413,9 @@ "dev": true }, "get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", "dev": true }, "glob": { diff --git a/package.json b/package.json index ab8e508..8263801 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adm-zip", - "version": "0.5.11", + "version": "0.5.12", "description": "Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk", "scripts": { "test": "mocha -R spec", diff --git a/zipEntry.js b/zipEntry.js index 5345ce1..8c3053b 100644 --- a/zipEntry.js +++ b/zipEntry.js @@ -15,8 +15,7 @@ module.exports = function (/*Buffer*/ input) { if (!input || !Buffer.isBuffer(input)) { return Buffer.alloc(0); } - //Scanning a local file headers is not necessary (except in the case of corrupted archives) - if(!_entryHeader.compressedSize) _entryHeader.loadDataHeaderFromBinary(input); + _entryHeader.loadDataHeaderFromBinary(input); return input.slice(_entryHeader.realDataOffset, _entryHeader.realDataOffset + _entryHeader.compressedSize); }