Skip to content
This repository was archived by the owner on Nov 9, 2020. It is now read-only.

Commit e0674a7

Browse files
committed
⚡ Zip: don't trust "getSize"
This method may return "-1", or wrong values. Relying on it is dangerous. + add a TODO item: limit the max file size? We don't want to hold more than X MB in memory, do we?
1 parent f68ff28 commit e0674a7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

module/module-zip/src/main/java/xyz/docbleach/module/zip/ArchiveBleach.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ private void sanitizeFile(BleachSession session, ZipInputStream zipIn, ZipOutput
7373
ByteArrayOutputStream streamBuilder = new ByteArrayOutputStream();
7474

7575
int bytesRead;
76-
byte[] tempBuffer = new byte[(int) entry.getSize()];
76+
// @TODO: check real file size?
77+
byte[] tempBuffer = new byte[1024];
7778
while ((bytesRead = zipIn.read(tempBuffer)) != -1) {
7879
streamBuilder.write(tempBuffer, 0, bytesRead);
7980
}
80-
ByteArrayOutputStream out = new ByteArrayOutputStream();
81-
8281
ByteArrayInputStream bais = new ByteArrayInputStream(streamBuilder.toByteArray());
8382
CloseShieldInputStream is = new CloseShieldInputStream(new BufferedInputStream(bais));
8483

84+
ByteArrayOutputStream out = new ByteArrayOutputStream();
85+
86+
8587
try {
8688
session.sanitize(is, out);
8789
} catch (RecursionBleachException e) {

0 commit comments

Comments
 (0)