snappy icon indicating copy to clipboard operation
snappy copied to clipboard

How should I validate encoded data?

Open chasehan-atlas opened this issue 4 years ago • 1 comments

Hey,

I try to use snappy with golang, I see JS and Java has a function named isValidCompressed which can validate the encoded buffer, but I can't see that function with golang. I am thinking to use decode function directly. And if it returns error, it means the encoded buffer is invalid. But I am not sure that's safe/correct or not. Such as below: byte[] bytes = Snappy.isValidCompressedBuffer(recordBytes) ? Snappy.uncompress(recordBytes) : recordBytes; Anyone have any ideas on how to safe and quickly validate the encoded buffer?

chasehan-atlas avatar Feb 22 '21 03:02 chasehan-atlas

Just decompress. But check if size is reasonable with DecodedLen first.

klauspost avatar Dec 07 '23 20:12 klauspost