Skip to content

Commit 425d13a

Browse files
committed
Fix inconsistencies in IS-CAB
1 parent 8a1e90f commit 425d13a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

SabreTools.Serialization/Wrappers/InstallShieldCabinet.Extraction.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,13 @@ public bool FileSave(int index, string filename, bool includeDebug, bool useOld
290290
ulong readBytesLeft = GetReadableBytes(fileDescriptor);
291291
ulong writeBytesLeft = GetWritableBytes(fileDescriptor);
292292
byte[] outputBuffer = new byte[BUFFER_SIZE];
293-
long totalWritten = 0;
293+
ulong totalWritten = 0;
294+
295+
// Cache the expected values
296+
ulong storedSize = readBytesLeft;
294297

295298
// Read while there are bytes remaining
296-
while (readBytesLeft > 0 && writeBytesLeft > 0)
299+
while (readBytesLeft > 0 && readBytesLeft <= storedSize)
297300
{
298301
uint bytesToWrite = BUFFER_SIZE;
299302
int result;
@@ -372,7 +375,7 @@ public bool FileSave(int index, string filename, bool includeDebug, bool useOld
372375
}
373376

374377
// Validate the number of bytes written
375-
if ((long)fileDescriptor.ExpandedSize != totalWritten)
378+
if (fileDescriptor.ExpandedSize != totalWritten)
376379
if (includeDebug) Console.WriteLine($"Expanded size of file {index} ({GetFileName(index)}) expected to be {fileDescriptor.ExpandedSize}, but was {totalWritten}");
377380

378381
// Finalize output values
@@ -466,7 +469,7 @@ private unsafe static int Uncompress(byte[] dest, ref uint destLen, byte[] sourc
466469
if (err != zlibConst.Z_OK)
467470
return err;
468471

469-
err = ZLib.inflate(stream, 1);
472+
err = ZLib.inflate(stream, zlibConst.Z_FINISH);
470473
if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END)
471474
{
472475
ZLib.inflateEnd(stream);
@@ -504,7 +507,7 @@ private unsafe static int UncompressOld(byte[] dest, ref uint destLen, byte[] so
504507

505508
while (stream.avail_in > 1)
506509
{
507-
err = ZLib.inflate(stream, 1);
510+
err = ZLib.inflate(stream, zlibConst.Z_BLOCK);
508511
if (err != zlibConst.Z_OK)
509512
{
510513
ZLib.inflateEnd(stream);
@@ -717,6 +720,7 @@ public bool Read(byte[] buffer, int start, long size)
717720
return false;
718721

719722
// Set the number of bytes left
723+
start += bytesToRead;
720724
bytesLeft -= bytesToRead;
721725
_volumeBytesLeft -= (uint)bytesToRead;
722726
}
@@ -777,7 +781,7 @@ private bool OpenVolume(ushort volume)
777781

778782
ulong volumeBytesLeftCompressed, volumeBytesLeftExpanded;
779783
#if NET20 || NET35
780-
if ((_fileDescriptor.Flags & FileFlags.FILE_SPLIT) != 0)
784+
if ((_fileDescriptor.Flags & FileFlags.FILE_SPLIT) != 0)
781785
#else
782786
if (_fileDescriptor.Flags.HasFlag(FileFlags.FILE_SPLIT))
783787
#endif

0 commit comments

Comments
 (0)