Fix MS-CAB block continuation

This commit is contained in:
Matt Nadareski
2025-07-30 15:18:27 -04:00
parent 93a6ab5b19
commit 8e745db34e

View File

@@ -276,14 +276,17 @@ namespace BinaryObjectScanner.FileType
byte[] blockData = db.CompressedData;
// If the block is continued, append
bool continuedBlock = false;
if (db.UncompressedSize == 0)
{
var nextBlock = dataBlocks[i++];
var nextBlock = dataBlocks[i + 1];
byte[]? nextData = nextBlock.CompressedData;
if (nextData == null)
continue;
continuedBlock = true;
blockData = [.. blockData, .. nextData];
db.CompressedSize += nextBlock.CompressedSize;
db.UncompressedSize = nextBlock.UncompressedSize;
}
@@ -304,6 +307,9 @@ namespace BinaryObjectScanner.FileType
// Write the uncompressed data block
ms.Write(data, 0, data.Length);
ms.Flush();
// Increment additionally if we had a continued block
if (continuedBlock) i++;
}
return ms;