stangelandcl / LZ4Sharp

Unmaintained port of LZ4 Compression algorithm to C#
Other
61 stars 15 forks source link

System.AccessViolationException #10

Closed koraybayram closed 11 years ago

koraybayram commented 11 years ago

We used LZ4Sharp for xml string - at most 40Kbyte - compression application. It calls compress method about 50 million times. But we got System.AccessViolationException during the execution. There might be some problem about algorithm. Of course, it might be occured according to our usage.

Exception Info: System.AccessViolationException Stack: at LZ4Sharp.LZ4Compressor32.Compress(Byte, Byte, Int32, Int32) at LZ4Sharp.LZ4Compressor32.Compress(Byte[], Byte[]) at LZ4Sharp.LZ4Compressor32.Compress(Byte[]) at Common.XmlCompresser.Compress(System.String)

Our Usage:

public class XmlCompresser
{
    private static ILZ4Compressor compressor = LZ4CompressorFactory.CreateNew();

    private static string Compress(string xml)
    {
        var decompressedDataBytes = Encoding.UTF8.GetBytes(xml);
        var compressedDataBytes = compressor.Compress(decompressedDataBytes);
        return Convert.ToBase64String(compressedDataBytes);
    }
}
stangelandcl commented 11 years ago

Is it possible for you to attach the xml as a file? If not maybe you could find just a small chunk of it that fails or some binary data that fails. I will try to generate some strings in the 0 - 40 KB range and see if I can reproduce it.

koraybayram commented 11 years ago

Xml files are generated dynamically from database. So I cannot attach a sample file. But I think, any xml file can be used to test it.

stangelandcl commented 11 years ago

I tried some xml files and still cannot reproduce it. You could just save the string to a file to post to github but maybe the data in the database should not be shared on the internet. Looking closer at your code, it would probably fail if used from multiple threads. Is that possibly the problem? The LZ4 Compressors and Decompressors are not threadsafe and need to be created for each thread or for each time they are used if used by multiple threads. Or you can call the static functions in the LZ4 class. They create and use a new compressor and decompressor on each call.

koraybayram commented 11 years ago

We used global compressor with multiple threads. we will change our code as compressor(decompressor for each thread. Thanks for your help.