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: check that data is large enough to fit header and mac #7118

Merged
merged 1 commit into from Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/net/ecies/src/algorithm.rs
Expand Up @@ -637,6 +637,13 @@ impl ECIES {
}

pub fn read_header(&mut self, data: &mut [u8]) -> Result<usize, ECIESError> {
// If the data is not large enough to fit the header and mac bytes, return an error
//
// The header is 16 bytes, and the mac is 16 bytes, so the data must be at least 32 bytes
if data.len() < 32 {
return Err(ECIESErrorImpl::InvalidHeader.into())
}

let (header_bytes, mac_bytes) = split_at_mut(data, 16)?;
let header = HeaderBytes::from_mut_slice(header_bytes);
let mac = B128::from_slice(&mac_bytes[..16]);
Expand Down