zlib: validate central directory record count · nodejs/node@575260d · GitHub
Skip to content

Commit 575260d

Browse files
mcollinaaduh95
authored andcommitted
zlib: validate central directory record count
ZIP readers trusted the EOCD record count. They did not check that the parsed headers consumed the declared central directory size. Reject archives whose count leaves directory bytes unparsed. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #65002 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 8e848d9 commit 575260d

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

lib/internal/zip/entry.js

Lines changed: 4 additions & 0 deletions

lib/internal/zip/headers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ function readCentralDirectory(buffer, count) {
553553
ArrayPrototypePush(result, header);
554554
pos += header.byteLength;
555555
}
556+
if (pos !== buffer.length) {
557+
throw new ERR_ZIP_INVALID_ARCHIVE(
558+
'central directory record count is inconsistent with its size');
559+
}
556560
return result;
557561
}
558562

test/parallel/test-zlib-zip-security.js

Lines changed: 34 additions & 0 deletions

0 commit comments

Comments
 (0)