Skip to content

Commit 8e745db

Browse files
committed
Fix MS-CAB block continuation
1 parent 93a6ab5 commit 8e745db

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

BinaryObjectScanner/FileType/MicrosoftCAB.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,17 @@ private static void ExtractFile(string outDir, Stream blockStream, CFFILE file,
276276
byte[] blockData = db.CompressedData;
277277

278278
// If the block is continued, append
279+
bool continuedBlock = false;
279280
if (db.UncompressedSize == 0)
280281
{
281-
var nextBlock = dataBlocks[i++];
282+
var nextBlock = dataBlocks[i + 1];
282283
byte[]? nextData = nextBlock.CompressedData;
283284
if (nextData == null)
284285
continue;
285286

287+
continuedBlock = true;
286288
blockData = [.. blockData, .. nextData];
289+
db.CompressedSize += nextBlock.CompressedSize;
287290
db.UncompressedSize = nextBlock.UncompressedSize;
288291
}
289292

@@ -304,6 +307,9 @@ private static void ExtractFile(string outDir, Stream blockStream, CFFILE file,
304307
// Write the uncompressed data block
305308
ms.Write(data, 0, data.Length);
306309
ms.Flush();
310+
311+
// Increment additionally if we had a continued block
312+
if (continuedBlock) i++;
307313
}
308314

309315
return ms;

0 commit comments

Comments
 (0)