Skip to content

Commit bd83f19

Browse files
committed
Fixed extraction bug
1 parent 4a684a2 commit bd83f19

File tree

4 files changed

+29
-51
lines changed

4 files changed

+29
-51
lines changed

headers/entryHeader.js

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -170,60 +170,39 @@ module.exports = function () {
170170
},
171171

172172
get realDataOffset() {
173-
return _offset + Constants.LOCHDR + _fnameLen + _extraLen;
173+
return _offset + Constants.LOCHDR + _dataHeader.fnameLen + _dataHeader.extraLen;
174174
},
175175

176176
get dataHeader() {
177+
return _dataHeader;
178+
},
179+
180+
loadDataHeaderFromBinary: function (/*Buffer*/ input) {
181+
var data = input.slice(_offset, _offset + Constants.LOCHDR);
182+
// 30 bytes and should start with "PK\003\004"
183+
if (data.readUInt32LE(0) !== Constants.LOCSIG) {
184+
throw new Error(Utils.Errors.INVALID_LOC);
185+
}
177186
_dataHeader = {
178187
// version needed to extract
179-
version: _version,
188+
version: data.readUInt16LE(Constants.LOCVER),
180189
// general purpose bit flag
181-
flags: _flags,
190+
flags: data.readUInt16LE(Constants.LOCFLG),
182191
// compression method
183-
method: _method,
192+
method: data.readUInt16LE(Constants.LOCHOW),
184193
// modification time (2 bytes time, 2 bytes date)
185-
time: _time,
194+
time: data.readUInt32LE(Constants.LOCTIM),
186195
// uncompressed file crc-32 value
187-
crc: _crc,
196+
crc: data.readUInt32LE(Constants.LOCCRC),
188197
// compressed size
189-
compressedSize: _compressedSize,
198+
compressedSize: data.readUInt32LE(Constants.LOCSIZ),
190199
// uncompressed size
191-
size: _size,
200+
size: data.readUInt32LE(Constants.LOCLEN),
192201
// filename length
193-
fnameLen: _fnameLen,
202+
fnameLen: data.readUInt16LE(Constants.LOCNAM),
194203
// extra field length
195-
extraLen: _extraLen
204+
extraLen: data.readUInt16LE(Constants.LOCEXT)
196205
};
197-
198-
return _dataHeader;
199-
},
200-
201-
loadDataHeaderFromBinary: function (/*Buffer*/ input) {
202-
var data = input.slice(_offset, _offset + Constants.LOCHDR);
203-
// 30 bytes and should start with "PK\003\004"
204-
if (data.readUInt32LE(0) !== Constants.LOCSIG) {
205-
throw new Error(Utils.Errors.INVALID_LOC);
206-
}
207-
208-
// version needed to extract
209-
_version = data.readUInt16LE(Constants.LOCVER);
210-
// general purpose bit flag
211-
_flags = data.readUInt16LE(Constants.LOCFLG);
212-
// compression method
213-
_method = data.readUInt16LE(Constants.LOCHOW);
214-
// modification time (2 bytes time, 2 bytes date)
215-
_time = data.readUInt32LE(Constants.LOCTIM);
216-
// uncompressed file crc-32 value
217-
_crc = data.readUInt32LE(Constants.LOCCRC);
218-
// compressed size
219-
_compressedSize = data.readUInt32LE(Constants.LOCSIZ);
220-
// uncompressed size
221-
_size = data.readUInt32LE(Constants.LOCLEN);
222-
// filename length
223-
_fnameLen = data.readUInt16LE(Constants.LOCNAM);
224-
// extra field length
225-
_extraLen = data.readUInt16LE(Constants.LOCEXT);
226-
227206
},
228207

229208
loadFromBinary: function (/*Buffer*/ data) {

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "adm-zip",
3-
"version": "0.5.11",
3+
"version": "0.5.12",
44
"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",
55
"scripts": {
66
"test": "mocha -R spec",

zipEntry.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ module.exports = function (/*Buffer*/ input) {
1515
if (!input || !Buffer.isBuffer(input)) {
1616
return Buffer.alloc(0);
1717
}
18-
//Scanning a local file headers is not necessary (except in the case of corrupted archives)
19-
if(!_entryHeader.compressedSize) _entryHeader.loadDataHeaderFromBinary(input);
18+
_entryHeader.loadDataHeaderFromBinary(input);
2019
return input.slice(_entryHeader.realDataOffset, _entryHeader.realDataOffset + _entryHeader.compressedSize);
2120
}
2221

0 commit comments

Comments
 (0)