Skip to content

Commit 12e8349

Browse files
committed
Pad short MS-ZIP blocks
1 parent 3c05bec commit 12e8349

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

BinaryObjectScanner/FileType/MicrosoftCAB.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public bool Extract(Stream? stream, string file, string outDir, bool includeDebu
156156
{
157157
var db = dataBlocks[i];
158158
if (db?.CompressedData == null)
159-
continue;
159+
continue;
160160

161161
// Uncompressed data
162162
if ((folder.CompressionType & CompressionType.MASK_TYPE) == CompressionType.TYPE_NONE)
@@ -171,8 +171,14 @@ public bool Extract(Stream? stream, string file, string outDir, bool includeDebu
171171
long position = ms.Position;
172172
mszip.CopyTo(db.CompressedData, ms);
173173
long decompressedSize = ms.Position - position;
174-
if (decompressedSize != db.UncompressedSize)
175-
Console.Error.WriteLine($"Data block {i} in folder {folderIndex} did not decompress properly. Expected: {db.UncompressedSize} Got: {decompressedSize}");
174+
175+
// Pad to the correct size but throw a warning about this
176+
if (decompressedSize < db.UncompressedSize)
177+
{
178+
Console.Error.WriteLine($"Data block {i} in folder {folderIndex} had mismatching sizes. Expected: {db.UncompressedSize}, Got: {decompressedSize}");
179+
byte[] padding = new byte[db.UncompressedSize - decompressedSize];
180+
ms.Write(padding, 0, padding.Length);
181+
}
176182
}
177183

178184
// Quantum

0 commit comments

Comments
 (0)