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

Hash types conversions unhandled panics #2275

Open
Alrighttt opened this issue Nov 19, 2024 · 0 comments
Open

Hash types conversions unhandled panics #2275

Alrighttt opened this issue Nov 19, 2024 · 0 comments
Assignees
Labels
bug: security priority: urgent Critical tasks requiring immediate action.

Comments

@Alrighttt
Copy link
Member

Types such as H256 and H264 have methods that can cause a runtime panic.

This is due to Indexing into a slice without first checking the size of the slice:

inner[..].clone_from_slice(&slc[0..$size]);

ex:

use rpc::v1::types::H264;
let some_vec = vec![0u8];
let this_panics: H264 = some_vec.as_slice().into();

panicked at 'range end index 33 out of range for slice of length 1', mm2src/mm2_bitcoin/primitives/src/hash.rs:157:1

culprit:
https://github.com/KomodoPlatform/komodo-defi-framework/blob/4d0f812ac5089364de51f896e282c419019ac4f9/mm2src/mm2_bitcoin/primitives/src/hash.rs#L42C1-L48C10
https://github.com/KomodoPlatform/komodo-defi-framework/blob/4d0f812ac5089364de51f896e282c419019ac4f9/mm2src/mm2_bitcoin/rpc/src/v1/types/hash.rs#L34C1-L39C10

This From implementation must be replaced with TryFrom or made infallible. Additionally there is an instance of .unwrap() in From<&'static str> for each hash type.

These types originate from parity bitcoin. I believe the macros for implementing these are implementing far more types than we utilize. We should consider minimizing the use of this hash module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: security priority: urgent Critical tasks requiring immediate action.
Projects
None yet
Development

No branches or pull requests

3 participants