faster-hex icon indicating copy to clipboard operation
faster-hex copied to clipboard

`hex_decode` silently allows shorter decoding

Open mmastrac opened this issue 2 years ago • 2 comments

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");
}

mmastrac avatar Mar 07 '24 14:03 mmastrac

I think the documentation is wrong, it should be:

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

eval-exec avatar Mar 07 '24 14:03 eval-exec

#47 closes this issue.

billf avatar Apr 22 '25 16:04 billf