Simplify guarding against corrupt ZIP files

Signed-off-by: Otto Sichert <git@ottosichert.de>
This commit is contained in:
Otto Sichert
2022-06-16 00:40:26 +02:00
committed by blam
parent 72e34fe980
commit 9344fdf1b6
@@ -26,6 +26,14 @@ import {
} from '../types';
import { streamToTimeoutPromise } from './util';
const guardCorruptZipStream = (stream: Readable) =>
streamToTimeoutPromise(stream, {
eventName: 'entry',
timeoutMs: 3000,
getError: (entry: Entry) =>
new Error(`Timed out while unzipping ${entry.type}: ${entry.path}`),
});
/**
* Wraps a zip archive stream into a tree response reader.
*/
@@ -104,13 +112,7 @@ export class ZipArchiveResponse implements ReadTreeResponse {
entry.autodrain();
}
});
await streamToTimeoutPromise(parseStream, {
eventName: 'entry',
timeoutMs: 3000,
getError: (entry: Entry) =>
new Error(`Timed out while unzipping ${entry.type}: ${entry.path}`),
});
await guardCorruptZipStream(parseStream);
return files;
}
@@ -132,13 +134,7 @@ export class ZipArchiveResponse implements ReadTreeResponse {
entry.autodrain();
}
});
await streamToTimeoutPromise(parseStream, {
eventName: 'entry',
timeoutMs: 3000,
getError: (entry: Entry) =>
new Error(`Timed out while unzipping ${entry.type}: ${entry.path}`),
});
await guardCorruptZipStream(parseStream);
archive.finalize();
@@ -168,13 +164,7 @@ export class ZipArchiveResponse implements ReadTreeResponse {
entry.autodrain();
}
});
await streamToTimeoutPromise(parseStream, {
eventName: 'entry',
timeoutMs: 3000,
getError: (entry: Entry) =>
new Error(`Timed out while unzipping ${entry.type}: ${entry.path}`),
});
await guardCorruptZipStream(parseStream);
return dir;
}