As the subject states - I have a data block which is 0x100043 in length that decompresses to 0x100000 fine in C++ (code below), but exceptions with a bad data error in Lzma2Dec_DecodeToDic() line 323 when using managed lzma.
It could be possible I am using the API incorrectly, that would be the first thing to verify.
The Lzma2Dec_DecodeToDic functions in managed lzma and C++ lzma 1900 are just different enough that there's no easy change to make things work. It looks like the C# is a direct port of a different version of the C++.
TEST_METHOD_CATEGORY( SimpleDecompressBlob, "SevenZip" )
{
Log( "7-zip decompress blob test" );
SetWorkingDirectoryForTests();
size_t source_length = 0;
uint8* compressed_memory = LoadFileToMemory( "TestData/Binary.dat", &source_length );
size_t dest_length = 1024 * 1024;
uint8* dest = static_cast< uint8* >( calloc( 1, dest_length ) );
ISzAlloc alloc = { SevenZipMalloc, SevenZipFree };
ELzmaStatus status = LZMA_STATUS_NOT_SPECIFIED;
SRes result = Lzma2Decode( dest, &dest_length, compressed_memory, &source_length, 12, ELzmaFinishMode::LZMA_FINISH_END, &status, &alloc );
Assert::IsTrue( result == SZ_OK, L"Lzma2Decode returned error" );
free( dest );
}
C# code - which exceptions (for testing, I put this at the top of sandbox-7z Program.cs)
public class FLzma2Data
{
public byte[] SourceData = ( byte[] )null;
public int SourceOffset = -1;
public int SourceLength = -1;
public byte[] DestinationData = ( byte[] )null;
public int DestinationOffset = -1;
public int DestinationLength = -1;
public byte DictionarySize = 40;
}
[STAThread]
static void Main()
{
FLzma2Data data = new FLzma2Data();
FileInfo Info = new FileInfo( "d:/Temp/Binary.dat" );
BinaryReader reader = new BinaryReader( Info.OpenRead() );
data.SourceData = reader.ReadBytes( ( int )Info.Length );
data.SourceLength = ( int )Info.Length;
data.SourceOffset = 0;
reader.Close();
data.DestinationData = new byte[1024 * 1024];
data.DestinationLength = 1024 * 1024;
data.DestinationOffset = 0;
data.DictionarySize = 12;
ManagedLzma.LZMA2.Decoder decoder = new ManagedLzma.LZMA2.Decoder( new ManagedLzma.LZMA2.DecoderSettings( 12 ) );
decoder.Decode( data.SourceData, data.SourceOffset, data.SourceLength, data.DestinationLength, true );
decoder.ReadOutputData( data.DestinationData, data.DestinationOffset, data.DestinationLength );
I could send you the file, but I don't want to bog down the forum with a meg of uncompressable data =)