Hi,I am using the lib.Some of the files I compress are JPG and PNGs.For some reason I fail to understand,the method
`LZ4_compress_default`
Sometimes returns negative values for images I am compressing.For example,I am compressing two standard JPG images.One returns with a -236 ,while the second returns fine the number of compressed bytes.Why is it happening?
JPG and PNG are already compressed so trying to compress them almost pointless.
What is the purpose of compressing image files?
I am writing a sort of zip prog where I bundle different files into one compressed file.But I think my problem has been that I didn't take into consideration that the max size can be more than the source size.I suppose I solved the issue. http://stackoverflow.com/questions/41346669/lz4-compression-of-compressed-image-formats
Indeed, as you found, destination buffer must be sized with LZ4_compressBound() to guarantee compression operation success. If it's smaller, compression may occasionally fail if the compressed result cannot fit into destination buffer.
I'm nonetheless surprised it generated a _negative_ function result.
When compression fails, it should return 0.
I looked again at the code of LZ4_compress_default(), and couldn't find any way it could generate a negative return value. All error paths, therefore including "destination buffer is too small" use case, return 0.
So if this negative result is confirmed, it could be something interesting to debug. I would be glad to know more to be able to generate the same effect.


See two attached files.lz_toast when attemping to compress it,returns that value.I work with VC140 compiler,VS2015,64bit config .Windows10
I've been testing both images provided above, compressing them with LZ4_compress_default(), and checked the produced return code. I tried to make them compress into a destination buffer of same size as the original file size, which seems to be your original use case.
Greyscale image get nonetheless compressed, from 89070 to 72709 bytes.
The Color image is not compressed. Original size is 24159 bytes.
Trying to compress it into a buffer of same size results in a return code 0.
Trying to compress it into a buffer of size LZ4_compressBound(inputSize), the file is expanded to 24225 bytes.
I have not been able to observe any negative return code.
Have you found the source of your negative return code ?
Is it still worth keeping it as an opened issue ?
Closing for lack of feedback