faster-hex
faster-hex copied to clipboard
`hex_decode` silently allows shorter decoding
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");
}
I think the documentation is wrong, it should be:
/// The length of `dst` must be at least `src.len() / 2`.
#47 closes this issue.