Skip to content

Commit fa46308

Browse files
authored
Merge pull request #2673 from RunDevelopment/tga-wide-index-crash
Fixed TGA crash for images where indices have more bits than mapped colors
2 parents 8660412 + 33ebcca commit fa46308

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/codecs/tga/decoder.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {
18 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)