Skip to content

Commit ddc0094

Browse files
committed
Remove red herring zlib code
1 parent c96ee81 commit ddc0094

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

SabreTools.Serialization/Wrappers/InstallShieldCabinet.Extraction.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public partial class InstallShieldCabinet : IExtractable
176176
/// <param name="index">Cabinet part index to be opened</param>
177177
/// <param name="suffix">Cabinet files suffix (e.g. `.cab`)</param>
178178
/// <returns>A Stream representing the cabinet part, null on error</returns>
179-
private static Stream? OpenFileForReading(string? pattern, int index, string suffix)
179+
private static FileStream? OpenFileForReading(string? pattern, int index, string suffix)
180180
{
181181
// An invalid pattern means no cabinet files
182182
if (string.IsNullOrEmpty(pattern))
@@ -317,8 +317,8 @@ public bool FileSave(int index, string filename, bool includeDebug, bool useOld
317317
}
318318

319319
// Attempt to read the specified number of bytes
320-
ushort bytesToRead = BitConverter.ToUInt16(lengthArr, 0);
321-
inputBuffer = new byte[BUFFER_SIZE + 1];
320+
uint bytesToRead = BitConverter.ToUInt16(lengthArr, 0);
321+
inputBuffer = new byte[BUFFER_SIZE];
322322
if (!reader.Read(inputBuffer, 0, bytesToRead))
323323
{
324324
Console.Error.WriteLine($"Failed to read {lengthArr.Length} bytes of file {index} ({GetFileName(index)}) from input cabinet file {fileDescriptor.Volume}");
@@ -327,20 +327,16 @@ public bool FileSave(int index, string filename, bool includeDebug, bool useOld
327327
return false;
328328
}
329329

330-
// Add a null byte to make inflate happy
331-
inputBuffer[bytesToRead] = 0;
332-
ulong readBytes = (ulong)(bytesToRead + 1);
333-
334330
// Uncompress into a buffer
335331
if (useOld)
336-
result = UncompressOld(outputBuffer, ref bytesToWrite, inputBuffer, ref readBytes);
332+
result = UncompressOld(outputBuffer, ref bytesToWrite, inputBuffer, ref bytesToRead);
337333
else
338-
result = Uncompress(outputBuffer, ref bytesToWrite, inputBuffer, ref readBytes);
334+
result = Uncompress(outputBuffer, ref bytesToWrite, inputBuffer, ref bytesToRead);
339335

340336
// If we didn't get a positive result that's not a data error (false positives)
341337
if (result != zlibConst.Z_OK && result != zlibConst.Z_DATA_ERROR)
342338
{
343-
Console.Error.WriteLine($"Decompression failed with code {result.ToZlibConstName()}. bytes_to_read={bytesToRead}, volume={fileDescriptor.Volume}, read_bytes={readBytes}");
339+
Console.Error.WriteLine($"Decompression failed with code {result.ToZlibConstName()}. bytes_to_read={bytesToRead}, volume={fileDescriptor.Volume}, read_bytes={bytesToRead}");
344340
reader.Dispose();
345341
fs?.Close();
346342
return false;
@@ -454,14 +450,14 @@ public bool FileSaveRaw(int index, string filename)
454450
/// <summary>
455451
/// Uncompress a source byte array to a destination
456452
/// </summary>
457-
private unsafe static int Uncompress(byte[] dest, ref long destLen, byte[] source, ref ulong sourceLen)
453+
private unsafe static int Uncompress(byte[] dest, ref long destLen, byte[] source, ref uint sourceLen)
458454
{
459455
fixed (byte* sourcePtr = source, destPtr = dest)
460456
{
461457
var stream = new ZLib.z_stream_s
462458
{
463459
next_in = sourcePtr,
464-
avail_in = (uint)sourceLen,
460+
avail_in = sourceLen,
465461
next_out = destPtr,
466462
avail_out = (uint)destLen,
467463
};
@@ -487,14 +483,14 @@ private unsafe static int Uncompress(byte[] dest, ref long destLen, byte[] sourc
487483
/// <summary>
488484
/// Uncompress a source byte array to a destination (old version)
489485
/// </summary>
490-
private unsafe static int UncompressOld(byte[] dest, ref long destLen, byte[] source, ref ulong sourceLen)
486+
private unsafe static int UncompressOld(byte[] dest, ref long destLen, byte[] source, ref uint sourceLen)
491487
{
492488
fixed (byte* sourcePtr = source, destPtr = dest)
493489
{
494490
var stream = new ZLib.z_stream_s
495491
{
496492
next_in = sourcePtr,
497-
avail_in = (uint)sourceLen,
493+
avail_in = sourceLen,
498494
next_out = destPtr,
499495
avail_out = (uint)destLen,
500496
};

0 commit comments

Comments
 (0)