From cbae67b07d910d97ac689a00693cbf466dc2566a Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Mon, 29 Nov 2021 04:21:50 +0000 Subject: [PATCH] No bound checks when indexing during decoding --- src/decode.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/decode.rs b/src/decode.rs index f4250bd..75951f7 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -75,7 +75,10 @@ where let b1 = buf.read(); match b1 & QOI_MASK_2 { QOI_INDEX => { - px = index[usize::from(b1 ^ QOI_INDEX)]; + px = unsafe { + // Safety: (b1 ^ QOI_INDEX) is guaranteed to be at most 6 bits + *index.get_unchecked(usize::from(b1 ^ QOI_INDEX)) + }; } QOI_DIFF_8 => { px.rgb_add(