Skip to content

Commit

Permalink
Fixed extraction bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iacobnasca committed Mar 14, 2024
1 parent 4a684a2 commit bd83f19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 51 deletions.
59 changes: 19 additions & 40 deletions headers/entryHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 1 addition & 2 deletions zipEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit bd83f19

Please sign in to comment.