io/region: remove error handling for impossible cases from decode_chunk()

This commit is contained in:
Matthias Schiffer 2023-01-29 17:04:28 +01:00
parent 7c7e36f6be
commit 1d126ba771
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -43,11 +43,7 @@ where
T: DeserializeOwned,
{
let (len_bytes, buf) = buf.split_at(4);
let len = u32::from_be_bytes(
len_bytes
.try_into()
.context("Failed to decode chunk size")?,
) as usize;
let len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
if len < 1 || len > buf.len() {
bail!("Invalid chunk size");
@ -55,7 +51,7 @@ where
let buf = &buf[..len];
let (format, buf) = buf.split_at(1);
if !matches!(format, [2]) {
if format[0] != 2 {
bail!("Unknown chunk format");
}