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

crypto: variable-length hash algorithms do not throw errors for non-integer/non-safe-integer lengths, tests cases assume they do, but test logic is broken and suppresses the assertion failures #3798

Closed
jeremyBanks opened this issue Nov 13, 2023 · 0 comments · Fixed by #3799
Labels
bug Something isn't working needs triage

Comments

@jeremyBanks
Copy link
Contributor

jeremyBanks commented Nov 13, 2023

@quentinadam and @iuioiua noticed in #3793 (comment) that the crypto_test.ts logic was failing to check that errors were being thrown when expected.

I've made a commit that fixes the test logic: jeremyBanks@e571f76. Upon fixing it, three tests start to fail for two cases each: the three variable-length hash algorithms, BLAKE3, SHAKE128, and SHAKE256 do not throw errors for the cases Non-integer length with options {"length":1.5}) (which they treat as length: 1) and Too-large length with options {"length":8.112963841460666e+31}) (which they treat as length: 0), but our current test cases expect them to throw errrors.

The test logic definitely needs to be fixed, so that commit should be applied, but obviously that can't be merged until we also fix the crypto.ts logic to perform the expected checks (which might be considered BREAKING if we're being super-pedantic, but is probably safe in practice), or to change the expected result.

Some might argue that that truncating 1.5 to 1 is okay (I would prefer it to be an error), but I think all would agree that any length that's too large to fit into 32 bits (usize for WASM targets) should throw an error instead of being truncated to 0.

@jeremyBanks jeremyBanks added bug Something isn't working needs triage labels Nov 13, 2023
@jeremyBanks jeremyBanks changed the title crypto: variable-length hash algorithms do not throw errors for non-integer/non-safe-integer lengths, but tests assume they do crypto: variable-length hash algorithms do not throw errors for non-integer/non-safe-integer lengths, tests cases assume they do, but test logic is broken and suppresses the assertion failures Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
1 participant