diff --git a/Aaru.Compression/Apple/KenCode.cs b/Aaru.Compression/Apple/KenCode.cs index 19b521179..cad5c2ac1 100644 --- a/Aaru.Compression/Apple/KenCode.cs +++ b/Aaru.Compression/Apple/KenCode.cs @@ -44,15 +44,15 @@ public partial class KenCode /// Decodes a buffer compressed with Apple's LZH /// Encoded buffer /// Buffer where to write the decoded data - /// The number of decoded bytes + /// The number of decoded bytes, or -1 on error 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; } } \ No newline at end of file diff --git a/Aaru.Compression/Apple/Lzh.cs b/Aaru.Compression/Apple/Lzh.cs index 8ed5277d0..ebea79c4f 100644 --- a/Aaru.Compression/Apple/Lzh.cs +++ b/Aaru.Compression/Apple/Lzh.cs @@ -44,15 +44,15 @@ public partial class Lzh /// Decodes a buffer compressed with Apple's LZH /// Encoded buffer /// Buffer where to write the decoded data - /// The number of decoded bytes + /// The number of decoded bytes, or -1 on error 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; } } \ No newline at end of file diff --git a/Aaru.Compression/StuffIt/ShrinkWrap.cs b/Aaru.Compression/StuffIt/ShrinkWrap.cs index f1af4abbc..bdf80b3a2 100644 --- a/Aaru.Compression/StuffIt/ShrinkWrap.cs +++ b/Aaru.Compression/StuffIt/ShrinkWrap.cs @@ -44,15 +44,15 @@ public partial class ShrinkWrap /// Decodes a buffer compressed with ShrinkWrapper's StuffIt /// Encoded buffer /// Buffer where to write the decoded data - /// The number of decoded bytes + /// The number of decoded bytes, or -1 on error 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; } } \ No newline at end of file diff --git a/Aaru.Compression/Zip/Blast.cs b/Aaru.Compression/Zip/Blast.cs index ad49d0bc3..de0837a0b 100644 --- a/Aaru.Compression/Zip/Blast.cs +++ b/Aaru.Compression/Zip/Blast.cs @@ -44,15 +44,15 @@ public partial class Blast /// Decodes a buffer compressed with PKWARE's Data Compression Library Implode /// Encoded buffer /// Buffer where to write the decoded data - /// The number of decoded bytes + /// The number of decoded bytes, or -1 on error 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; } } \ No newline at end of file diff --git a/Aaru.Images/NDIF/Read.cs b/Aaru.Images/NDIF/Read.cs index f8bbc3c11..f9679a830 100644 --- a/Aaru.Images/NDIF/Read.cs +++ b/Aaru.Images/NDIF/Read.cs @@ -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; diff --git a/Aaru.Images/UDIF/Read.cs b/Aaru.Images/UDIF/Read.cs index 1f3803282..afb95b0d9 100644 --- a/Aaru.Images/UDIF/Read.cs +++ b/Aaru.Images/UDIF/Read.cs @@ -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;