Skip to content

Commit

Permalink
add support for truncated appended data
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed Nov 16, 2023
1 parent 2a10dda commit 5890f47
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/core/zip-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,14 @@ class ZipReader {
}
directoryDataOffset -= directoryDataLength;
}
if (directoryDataOffset >= reader.size) {
prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
}
if (expectedLastDiskNumber != lastDiskNumber) {
throw new Error(ERR_SPLIT_ZIP_FILE);
}
if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
if (directoryDataOffset < 0) {
throw new Error(ERR_BAD_FORMAT);
}
let offset = 0;
Expand All @@ -221,7 +225,7 @@ class ZipReader {
if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
const originalDirectoryDataOffset = directoryDataOffset;
directoryDataOffset = expectedDirectoryDataOffset;
prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
prependedDataLength += directoryDataOffset - originalDirectoryDataOffset;
directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength, diskNumber);
directoryView = getDataView(directoryArray);
}
Expand Down

0 comments on commit 5890f47

Please sign in to comment.