-
Notifications
You must be signed in to change notification settings - Fork 110
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
fix: verify length and hashes of fetched bytes before parsing #325
fix: verify length and hashes of fetched bytes before parsing #325
Conversation
22abd01
to
0e78e98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we add a few simple unit tests for BytesMatchLenAndHashes
and VersionEqual
in util_tests.go
, so we know in case they break at some point 👍 Other than that, it's great 👍 🙏
Add BytesMatchLenAndHashes() to verify that fetched bytes match the expected length and hashes. This is useful to check data before parsing. Signed-off-by: Joshua Lock <[email protected]>
Signed-off-by: Joshua Lock <[email protected]>
Signed-off-by: Joshua Lock <[email protected]>
Signed-off-by: Joshua Lock <[email protected]>
We check the length and hashes of the fetched bytes before parsing them, therefore once the data are parsed into a FileMeta we only need to check against the expected version. The length and hashes checks are no longer required at this point, as they have already been done. Signed-off-by: Joshua Lock <[email protected]>
Signed-off-by: Joshua Lock <[email protected]>
0e78e98
to
06b905d
Compare
Add tests for newly exported functions in the util package: * VersionEqual() - simple test of version number comparison * BytesMatchLenAndHashes() - check function returns appropriate errors when incorrect length, hashes, or both are passed Signed-off-by: Joshua Lock <[email protected]>
06b905d
to
af46f5d
Compare
I've add some tests in af46f5d and removed the unnecessary PTAL @mnm678 @znewman01 @rdimitrov 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 👍 LGTM! 💯
Fixes #233
Release Notes:
Check hashes and length of downloaded snapshot and targets metadata before parsing.
Types of changes:
Description of the changes being introduced by the pull request:
Better match the specification by performing checks against length and hashes on the downloaded bytes before parsing the bytes into a FileMeta.
Please verify and check that the pull request fulfills the following requirements: