File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -381,9 +381,22 @@ impl<R: Read> ImageDecoder for TgaDecoder<R> {
381381
382382 // Decode the raw data
383383 //
384- // We have already checked in `TgaDecoder::new` that the indices take less space than the
384+ // We currently assume that the indices take less space than the
385385 // pixels they encode, so it is safe to read the raw data into `buf`.
386+ if self . raw_bytes_per_pixel > self . color_type . bytes_per_pixel ( ) . into ( ) {
387+ return Err ( ImageError :: Unsupported (
388+ UnsupportedError :: from_format_and_kind (
389+ ImageFormat :: Tga . into ( ) ,
390+ UnsupportedErrorKind :: GenericFeature (
391+ "Color-mapped images with indices wider than color are not supported"
392+ . into ( ) ,
393+ ) ,
394+ ) ,
395+ ) ) ;
396+ }
386397 let num_raw_bytes = self . width * self . height * self . raw_bytes_per_pixel ;
398+ debug_assert ! ( num_raw_bytes <= buf. len( ) ) ;
399+
387400 if self . image_type . is_encoded ( ) {
388401 self . read_encoded_data ( & mut buf[ ..num_raw_bytes] ) ?;
389402 } else {
You can’t perform that action at this time.
0 commit comments