Implement manual catching of corrupted ZIP files
Co-authored-by: Emma Indal <emma.indahl@gmail.com> Co-authored-by: Anders Näsman <realandersn@users.noreply.github.com> Co-authored-by: Raghunandan Balachandran <soapraj@users.noreply.github.com> Signed-off-by: Otto Sichert <git@ottosichert.de>
This commit is contained in:
@@ -86,9 +86,22 @@ export class ZipArchiveResponse implements ReadTreeResponse {
|
||||
|
||||
const files = Array<ReadTreeResponseFile>();
|
||||
|
||||
await this.stream
|
||||
.pipe(unzipper.Parse())
|
||||
// Some corrupted ZIP files cause the zlib inflater to hang indefinitely.
|
||||
// This is a workaround to bail on stuck streams after 3 seconds.
|
||||
const piped = this.stream.pipe(unzipper.Parse());
|
||||
let lastEntryTimeout: NodeJS.Timeout | undefined;
|
||||
|
||||
await piped
|
||||
.on('entry', (entry: Entry) => {
|
||||
clearTimeout(lastEntryTimeout);
|
||||
|
||||
lastEntryTimeout = setTimeout(() => {
|
||||
piped.emit(
|
||||
'error',
|
||||
new Error(`Timed out unzipping file ${entry.path}`),
|
||||
);
|
||||
}, 3000);
|
||||
|
||||
if (entry.type === 'Directory') {
|
||||
entry.resume();
|
||||
return;
|
||||
@@ -105,6 +118,8 @@ export class ZipArchiveResponse implements ReadTreeResponse {
|
||||
})
|
||||
.promise();
|
||||
|
||||
clearTimeout(lastEntryTimeout);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user