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

Return an error if a decoded slice length doesn't fit into usize #491

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/de/mod.rs
Expand Up @@ -236,5 +236,7 @@ pub(crate) fn decode_option_variant<D: Decoder>(
/// Decodes the length of any slice, container, etc from the decoder
#[inline]
pub(crate) fn decode_slice_len<D: Decoder>(decoder: &mut D) -> Result<usize, DecodeError> {
u64::decode(decoder).map(|v| v as usize)
let v = u64::decode(decoder)?;

v.try_into().map_err(|_| DecodeError::SliceLength(v))
}
3 changes: 3 additions & 0 deletions src/error.rs
Expand Up @@ -116,6 +116,9 @@ pub enum DecodeError {
found: usize,
},

/// The encoded slice length doesn't fit into the decoded usize type.
SliceLength(u64),

/// Tried to decode an enum with no variants
EmptyEnum {
/// The type that was being decoded
Expand Down