mirror of
https://github.com/aaru-dps/Aaru.git
synced 2026-11-13 16:01:40 +00:00
[Compression] Stop ignoring the status returned by the native Apple LZH, KenCode, ShrinkWrap and Blast functions, returning -1 on error, and fail reading UDIF and NDIF sectors when any of their decompressors fails.
This commit is contained in:
@@ -44,15 +44,15 @@ public partial class KenCode
|
||||
/// <summary>Decodes a buffer compressed with Apple's LZH</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
/// <param name="destination">Buffer where to write the decoded data</param>
|
||||
/// <returns>The number of decoded bytes</returns>
|
||||
/// <returns>The number of decoded bytes, or -1 on error</returns>
|
||||
public static int DecodeBuffer(byte[] source, byte[] destination)
|
||||
{
|
||||
if(!Native.IsSupported) return 0;
|
||||
|
||||
nuint destLen = (nuint)destination.Length;
|
||||
|
||||
AARU_kencode_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
int res = AARU_kencode_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
|
||||
return (int)destLen;
|
||||
return res == 0 ? (int)destLen : -1;
|
||||
}
|
||||
}
|
||||
@@ -44,15 +44,15 @@ public partial class Lzh
|
||||
/// <summary>Decodes a buffer compressed with Apple's LZH</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
/// <param name="destination">Buffer where to write the decoded data</param>
|
||||
/// <returns>The number of decoded bytes</returns>
|
||||
/// <returns>The number of decoded bytes, or -1 on error</returns>
|
||||
public static int DecodeBuffer(byte[] source, byte[] destination)
|
||||
{
|
||||
if(!Native.IsSupported) return 0;
|
||||
|
||||
nuint destLen = (nuint)destination.Length;
|
||||
|
||||
AARU_apple_lzh_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
int res = AARU_apple_lzh_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
|
||||
return (int)destLen;
|
||||
return res == 0 ? (int)destLen : -1;
|
||||
}
|
||||
}
|
||||
@@ -44,15 +44,15 @@ public partial class ShrinkWrap
|
||||
/// <summary>Decodes a buffer compressed with ShrinkWrapper's StuffIt</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
/// <param name="destination">Buffer where to write the decoded data</param>
|
||||
/// <returns>The number of decoded bytes</returns>
|
||||
/// <returns>The number of decoded bytes, or -1 on error</returns>
|
||||
public static int DecodeBuffer(byte[] source, byte[] destination)
|
||||
{
|
||||
if(!Native.IsSupported) return 0;
|
||||
|
||||
nuint destLen = (nuint)destination.Length;
|
||||
|
||||
AARU_stuffit_shrinkwrap_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
int res = AARU_stuffit_shrinkwrap_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
|
||||
return (int)destLen;
|
||||
return res == 0 ? (int)destLen : -1;
|
||||
}
|
||||
}
|
||||
@@ -44,15 +44,15 @@ public partial class Blast
|
||||
/// <summary>Decodes a buffer compressed with PKWARE's Data Compression Library Implode</summary>
|
||||
/// <param name="source">Encoded buffer</param>
|
||||
/// <param name="destination">Buffer where to write the decoded data</param>
|
||||
/// <returns>The number of decoded bytes</returns>
|
||||
/// <returns>The number of decoded bytes, or -1 on error</returns>
|
||||
public static int DecodeBuffer(byte[] source, byte[] destination)
|
||||
{
|
||||
if(!Native.IsSupported) return 0;
|
||||
|
||||
nuint destLen = (nuint)destination.Length;
|
||||
|
||||
AARU_zip_blast_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
int res = AARU_zip_blast_decode_buffer(source, (nuint)source.Length, destination, ref destLen);
|
||||
|
||||
return (int)destLen;
|
||||
return res == 0 ? (int)destLen : -1;
|
||||
}
|
||||
}
|
||||
@@ -330,7 +330,10 @@ public sealed partial class Ndif
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
realSize = ADC.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
@@ -340,7 +343,10 @@ public sealed partial class Ndif
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
realSize = Rle.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
@@ -350,7 +356,10 @@ public sealed partial class Ndif
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
realSize = Lzh.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
@@ -360,7 +369,10 @@ public sealed partial class Ndif
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
realSize = KenCode.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
@@ -370,7 +382,10 @@ public sealed partial class Ndif
|
||||
{
|
||||
var tmpBuffer = new byte[_bufferSize];
|
||||
realSize = ShrinkWrap.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
|
||||
@@ -541,28 +541,40 @@ public sealed partial class Udif
|
||||
case CHUNK_TYPE_ADC:
|
||||
tmpBuffer = new byte[_buffersize];
|
||||
realSize = ADC.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
case CHUNK_TYPE_RLE:
|
||||
tmpBuffer = new byte[_buffersize];
|
||||
realSize = Rle.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
case CHUNK_TYPE_LZH:
|
||||
tmpBuffer = new byte[_buffersize];
|
||||
realSize = Lzh.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
case CHUNK_TYPE_KENCODE:
|
||||
tmpBuffer = new byte[_buffersize];
|
||||
realSize = KenCode.DecodeBuffer(cmpBuffer, tmpBuffer);
|
||||
data = new byte[realSize];
|
||||
|
||||
if(realSize < 0) return ErrorNumber.InOutError;
|
||||
|
||||
data = new byte[realSize];
|
||||
Array.Copy(tmpBuffer, 0, data, 0, realSize);
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user