From d7c8346e394f4d2c3500bc0291d5f840112b2430 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Wed, 1 Dec 2021 16:01:17 +0000 Subject: [PATCH] Error::BadDecodingDataSize -> InputBufferTooSmall --- src/decode.rs | 5 ++++- src/error.rs | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index cb3eec8..669599b 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -36,7 +36,10 @@ where Pixel: SupportedChannels, { if data.len() < QOI_HEADER_SIZE + QOI_PADDING { - return Err(Error::BadDecodingDataSize { size: data.len() }); + return Err(Error::InputBufferTooSmall { + size: data.len(), + required: QOI_HEADER_SIZE + QOI_PADDING, + }); } let header = Header::from_bytes(unsafe { // Safety: Header is a POD type and we have just checked that the data fits it diff --git a/src/error.rs b/src/error.rs index 1cefaa6..58a5b4f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,14 +2,14 @@ use std::error::Error as StdError; use std::fmt::{self, Display}; use std::result::Result as StdResult; -use crate::consts::{QOI_HEADER_SIZE, QOI_MAGIC, QOI_PADDING}; +use crate::consts::QOI_MAGIC; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Error { InvalidChannels { channels: u8 }, EmptyImage { width: u32, height: u32 }, BadEncodingDataSize { size: usize, expected: usize }, - BadDecodingDataSize { size: usize }, + InputBufferTooSmall { size: usize, required: usize }, OutputBufferTooSmall { size: usize, required: usize }, InvalidMagic { magic: u32 }, // TODO: invalid colorspace @@ -29,9 +29,8 @@ impl Display for Error { Self::BadEncodingDataSize { size, expected } => { write!(f, "bad data size when encoding: {} (expected: {})", size, expected) } - Self::BadDecodingDataSize { size } => { - let min_size = QOI_HEADER_SIZE + QOI_PADDING; - write!(f, "bad data size when decoding: {} (minimum required: {})", size, min_size) + Self::InputBufferTooSmall { size, required } => { + write!(f, "input buffer size too small: {} (minimum required: {})", size, required) } Self::OutputBufferTooSmall { size, required } => { write!(f, "output buffer size too small: {} (minimum required: {})", size, required)