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

hex_decode silently allows shorter decoding #46

Open
mmastrac opened this issue Mar 7, 2024 · 1 comment
Open

hex_decode silently allows shorter decoding #46

mmastrac opened this issue Mar 7, 2024 · 1 comment

Comments

@mmastrac
Copy link

mmastrac commented Mar 7, 2024

I'm not sure if the documentation is incorrect, or if the check itself is wrong.

The documentation for hex_decode states the following:

/// The length of dst must be src.len() / 2.

However, the function quietly allows for shorter decoding (though not longer decoding):

use faster_hex; // 0.8.1;

pub fn main() {
  let mut dst: [u8; 2] = [0; 2];
  faster_hex::hex_decode(b"aa", &mut dst).expect_err("aa");
  faster_hex::hex_decode(b"aaaa", &mut dst).expect("aaaa");
  faster_hex::hex_decode(b"aaaaaa", &mut dst).expect_err("aaaaaa");
}
@eval-exec
Copy link
Collaborator

eval-exec commented Mar 7, 2024

I think the documentation is wrong, it should be:

/// The length of `dst` must be at least `src.len() / 2`.

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

No branches or pull requests

2 participants