Skip to content

Commit 211330f

Browse files
committed
In ZipOutputStream.PutNextEntry, account for AES overhead when calculating compressed entry size
1 parent 251f189 commit 211330f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs

+31-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,21 @@ public void PutNextEntry(ZipEntry entry)
327327
}
328328
else
329329
{
330-
WriteLeInt(entry.IsCrypted ? (int)entry.CompressedSize + ZipConstants.CryptoHeaderSize : (int)entry.CompressedSize);
330+
int entryCompressedSize = (int)entry.CompressedSize;
331+
332+
if (entry.IsCrypted)
333+
{
334+
if (entry.AESKeySize > 0)
335+
{
336+
entryCompressedSize += entry.AESOverheadSize;
337+
}
338+
else
339+
{
340+
entryCompressedSize += ZipConstants.CryptoHeaderSize;
341+
}
342+
}
343+
344+
WriteLeInt(entryCompressedSize);
331345
WriteLeInt((int)entry.Size);
332346
}
333347
}
@@ -372,7 +386,22 @@ public void PutNextEntry(ZipEntry entry)
372386
if (headerInfoAvailable)
373387
{
374388
ed.AddLeLong(entry.Size);
375-
ed.AddLeLong(entry.CompressedSize);
389+
390+
long entryCompressedSize = entry.CompressedSize;
391+
392+
if (entry.IsCrypted)
393+
{
394+
if (entry.AESKeySize > 0)
395+
{
396+
entryCompressedSize += entry.AESOverheadSize;
397+
}
398+
else
399+
{
400+
entryCompressedSize += ZipConstants.CryptoHeaderSize;
401+
}
402+
}
403+
404+
ed.AddLeLong(entryCompressedSize);
376405
}
377406
else
378407
{

0 commit comments

Comments
 (0)