-
Notifications
You must be signed in to change notification settings - Fork 3
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
Unchecked length can cause memory allocation error. #1
Comments
Damn, you're right; thank you! I think the best solution for now would be to avoid any explicit preallocation and push the bytes to the vector (since vector allocates in steps this shouldn't be relevant performance degradation): // Create buffer and fill it with `len` bytes
let mut data_buf = Vec::new();
for _ in 0..len.into() {
data_buf.push(*source.next().ok_or(Asn1DerError::LengthMismatch)?);
}
Ok(data_buf.into()) |
KizzyCode
added a commit
that referenced
this issue
Jun 13, 2019
So, |
This was referenced Jun 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When de-serializing bytes, an arbitrary length of the value can be specified. When building
data_buf
here:https://github.com/KizzyCode/asn1_der/blob/master/src/der/value.rs#L17
This can lead to memory crashes for arbitrary large length values. Perhaps an upper bound is required to prevent crashing applications when de serializing arbitrary byte arrays.
This can be reproduced in the following example:
The text was updated successfully, but these errors were encountered: