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

fix: compute sha1 on .jar files of size up to buffer.constants.MAX_LENGTH #600

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

adrobuta
Copy link
Contributor

@adrobuta adrobuta commented Aug 1, 2024

Because we currently decompress .jar files using adm-zip that does not support streaming,
we load the .jar file in memory using the Buffer class. Due to the current design,
we can read .jar files of up to buffer.constants.MAX_LENGTH. On 32-bit architectures, this value
currently is 230 - 1 (about 1 GiB). On 64-bit architectures, this value currently is 232 (about 4 GiB).

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

Refactors buffertoSha1 function to support hashing of large buffers by reading the buffer in chunks. This fixes the case the crypto module is throwing The RangeError: data is too longbecause it cannot handle the size of data passed to it in one go. However due to the current design, we support hasing .jar files of up to buffer.constants.MAX_LENGTH.

Additional questions

@adrobuta adrobuta requested a review from a team as a code owner August 1, 2024 09:22
@adrobuta adrobuta force-pushed the fix/hash-large-files branch 3 times, most recently from a9128e8 to 8cc42dd Compare August 2, 2024 10:45
 Because we currently decompress .jar files using adm-zip that does not support streaming,
 we currently load the .jar file in memory using the Buffer class. Due to the current design,
 we can read .jar files of up to buffer.constants.MAX_LENGTH.
 On 32-bit architectures, this value currently is 230 - 1 (about 1 GiB).
 On 64-bit architectures, this value currently is 232 (about 4 GiB). UNIFY-158
@adrobuta adrobuta merged commit 73bc4cb into main Aug 5, 2024
15 checks passed
@adrobuta adrobuta deleted the fix/hash-large-files branch August 5, 2024 13:56
@snyk-team-unify
Copy link

🎉 This PR is included in version 6.13.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants