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 Array::resize_raw() to allow resizing to the length of the array. #63

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

edmonds
Copy link
Contributor

@edmonds edmonds commented Feb 19, 2025

The new_len parameter to Array::resize_raw() is the new length of the contained octets sequence. The documentation for resize_raw() specifies that it is an error for new_len to be larger than the array size, but the current code also returns an error if new_len is equal to the array size.

The following code will cause a panic with octseq 0.5.2, for instance if one were preparing an Array<512> buffer to receive a UDP DNS query message into.

use octseq::{array::Array, EmptyBuilder};

const UDP_DNS_QUERY_MAX_SIZE: usize = 512;

fn main() {
    let mut query_packet = Array::<UDP_DNS_QUERY_MAX_SIZE>::empty();
    query_packet.resize_raw(UDP_DNS_QUERY_MAX_SIZE).unwrap();
}

The `new_len` parameter to Array::resize_raw() is the new length of the
contained octets sequence. The documentation for resize_raw() specifies
that it is an error for `new_len` to be larger than the array size,
but the current code also returns an error if `new_len` is equal to the
array size.
Copy link
Member

@partim partim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Looks good.

@partim partim merged commit 651ac84 into NLnetLabs:main Mar 3, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants