golang / snappy

The Snappy compression format in the Go programming language.
BSD 3-Clause "New" or "Revised" License
1.52k stars 164 forks source link

How should I validate encoded data? #59

Open chasehan-atlas opened 3 years ago

chasehan-atlas commented 3 years ago

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?

klauspost commented 11 months ago

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