Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should I validate encoded data? #59

Open
chasehan-atlas opened this issue Feb 22, 2021 · 1 comment
Open

How should I validate encoded data? #59

chasehan-atlas opened this issue Feb 22, 2021 · 1 comment

Comments

@chasehan-atlas
Copy link

chasehan-atlas commented Feb 22, 2021

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants