From fb8a43fd13e4a9bed6a0a08d1e534e4497a57698 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Mon, 3 Jan 2022 13:04:22 +0300 Subject: [PATCH] Fix potential decoder panic when checking padding --- src/decode.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index 59ca777..8a53f4e 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -1,7 +1,7 @@ use std::io::Read; // TODO: can be removed once https://github.com/rust-lang/rust/issues/74985 is stable -use bytemuck::{cast_slice, cast_slice_mut, Pod}; +use bytemuck::{cast_slice_mut, Pod}; use crate::consts::{ QOI_HEADER_SIZE, QOI_OP_DIFF, QOI_OP_INDEX, QOI_OP_LUMA, QOI_OP_RGB, QOI_OP_RGBA, QOI_OP_RUN, @@ -81,7 +81,7 @@ where if unlikely(data.len() < QOI_PADDING_SIZE) { return Err(Error::UnexpectedBufferEnd); - } else if unlikely(cast_slice::<_, [u8; QOI_PADDING_SIZE]>(data)[0] != QOI_PADDING) { + } else if unlikely(&data[..QOI_PADDING_SIZE] != &QOI_PADDING) { return Err(Error::InvalidPadding); }