-
Notifications
You must be signed in to change notification settings - Fork 5.9k
fix(node/crypto): handle empty input in decipher final with auto_pad=false #31958
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
base: main
Are you sure you want to change the base?
Conversation
…false Co-authored-by: bartlomieju <[email protected]>
| if !input.is_empty() { | ||
| decryptor.decrypt_block_b2b_mut( | ||
| GenericArray::from_slice(input), | ||
| GenericArray::from_mut_slice(output), | ||
| ); | ||
| } |
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.
This would still panic if input is not 16 bytes right?
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.
@copilot Can you also handle input that is not 16 bytes? This should error not panic.
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.
Added validation to return DecipherError::InvalidFinalBlockLength when input length is not 16 bytes (for non-empty inputs). Also added a test case for this scenario. Commit: b397507
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.
@copilot Just use assert_block_len?
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.
Updated to use assert_block_len! macro. Commit: 311c212
…=false Co-authored-by: littledivy <[email protected]>
Co-authored-by: littledivy <[email protected]>
Co-authored-by: littledivy <[email protected]>
DecipherContext::finalwhen input is empty withauto_pad=falseauto_pad=falseassert_block_len!macro for consistencySummary
This PR fixes a panic in
node:cryptothat occurs when usingcreateDecipherivwithsetAutoPadding(false):Ok(())instead of panickingassert_block_len!macro to returnDecipherError::InvalidFinalBlockLengthinstead of panickingChanges:
ext/node/ops/crypto/cipher.rs: Added empty input checks and block length validation usingassert_block_len!macro for all affected cipher modes (Aes128Cbc, Aes128Ecb, Aes192Ecb, Aes256Ecb, Aes256Cbc) whenauto_pad=falsetests/unit_node/crypto/crypto_cipher_test.ts: Added regression tests for empty input and invalid block length scenarios for all affected cipher modesOriginal prompt
node:cryptopanics oncreateDecipheriv#31957💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.