mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-10-02 03:38:46 +00:00
RarStream Position fix, it was returning the file size. 7Zip CrcCheckStream always failed. Added a Solid Rar entry CRC test.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
@@ -21,16 +21,17 @@ namespace SharpCompress.Compressors.LZMA.Utilites
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (_mCurrentCrc != _mExpectedCrc)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
//Nanook - is not equal here - _mCurrentCrc is yet to be negated
|
||||
//if (_mCurrentCrc != _mExpectedCrc)
|
||||
//{
|
||||
// throw new InvalidOperationException();
|
||||
//}
|
||||
try
|
||||
{
|
||||
if (disposing && !_mClosed)
|
||||
{
|
||||
_mClosed = true;
|
||||
_mCurrentCrc = Crc.Finish(_mCurrentCrc);
|
||||
_mCurrentCrc = Crc.Finish(_mCurrentCrc); //now becomes equal
|
||||
#if DEBUG
|
||||
if (_mCurrentCrc == _mExpectedCrc)
|
||||
{
|
||||
@@ -40,6 +41,7 @@ namespace SharpCompress.Compressors.LZMA.Utilites
|
||||
{
|
||||
Debugger.Break();
|
||||
Debug.WriteLine("bad CRC");
|
||||
throw new InvalidOperationException(); //moved exception to here
|
||||
}
|
||||
|
||||
double lengthInv = 1.0 / _mLength;
|
||||
@@ -102,4 +104,4 @@ namespace SharpCompress.Compressors.LZMA.Utilites
|
||||
_mCurrentCrc = Crc.Update(_mCurrentCrc, buffer, offset, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable disable
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -23,6 +23,7 @@ namespace SharpCompress.Compressors.Rar
|
||||
private int outCount;
|
||||
private int outTotal;
|
||||
private bool isDisposed;
|
||||
private long _position;
|
||||
|
||||
public RarStream(IRarUnpack unpack, FileHeader fileHeader, Stream readStream)
|
||||
{
|
||||
@@ -32,6 +33,7 @@ namespace SharpCompress.Compressors.Rar
|
||||
fetch = true;
|
||||
unpack.DoUnpack(fileHeader, readStream, this);
|
||||
fetch = false;
|
||||
_position = 0;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -56,7 +58,8 @@ namespace SharpCompress.Compressors.Rar
|
||||
|
||||
public override long Length => fileHeader.UncompressedSize;
|
||||
|
||||
public override long Position { get => fileHeader.UncompressedSize - unpack.DestSize; set => throw new NotSupportedException(); }
|
||||
//commented out code always returned the length of the file
|
||||
public override long Position { get => _position; /* fileHeader.UncompressedSize - unpack.DestSize;*/ set => throw new NotSupportedException(); }
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
@@ -80,6 +83,7 @@ namespace SharpCompress.Compressors.Rar
|
||||
unpack.DoUnpack();
|
||||
fetch = false;
|
||||
}
|
||||
_position += (long)outTotal;
|
||||
return outTotal;
|
||||
}
|
||||
|
||||
@@ -129,4 +133,4 @@ namespace SharpCompress.Compressors.Rar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user