diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs index fdcd0df6..54c877e7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs @@ -30,6 +30,15 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } + private int UnpIO_UnpRead(byte[] buf, int offset, int count) { + // NOTE: caller has logic to check for -1 for error we throw instead. + return this.readStream.Read(buf, offset, count); + } + + private void UnpIO_UnpWrite(byte[] buf, size_t offset, uint count) { + this.writeStream.Write(buf, checked((int)offset), checked((int)count)); + } + public void DoUnpack(FileHeader fileHeader, Stream readStream, Stream writeStream) { // as of 12/2017 .NET limits array indexing to using a signed integer @@ -95,6 +104,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 public static byte[] EnsureCapacity(byte[] array, int length) { return array.Length < length ? new byte[length] : array; } + } } #endif \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs index b5eda3de..b362dae0 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs @@ -258,7 +258,7 @@ bool UnpReadBuf() DataSize=ReadTop; int ReadCode=0; if (BitInput.MAX_SIZE!=DataSize) - ReadCode=UnpIO->UnpRead(Inp.InBuf+DataSize,BitInput.MAX_SIZE-DataSize); + ReadCode=UnpIO_UnpRead(Inp.InBuf,DataSize,BitInput.MAX_SIZE-DataSize); if (ReadCode>0) // Can be also -1. ReadTop+=ReadCode; ReadBorder=ReadTop-30; @@ -359,7 +359,7 @@ void UnpWriteBuf() Filters[I].Type=FILTER_NONE; if (OutMem!=null) - UnpIO->UnpWrite(OutMem,BlockLength); + UnpIO_UnpWrite(OutMem,0,BlockLength); UnpSomeRead=true; WrittenFileSize+=BlockLength; @@ -549,7 +549,7 @@ void UnpWriteData(byte[] Data, size_t offset, size_t Size) int64 LeftToWrite=DestUnpSize-WrittenFileSize; if ((int64)WriteSize>LeftToWrite) WriteSize=(size_t)LeftToWrite; - UnpIO->UnpWrite(Data, offset, WriteSize); + UnpIO_UnpWrite(Data, offset, WriteSize); WrittenFileSize+=Size; }