Skip to content

Commit 9596668

Browse files
authored
Raise proper error when decoding 16-bits jpegs (#4101)
1 parent d1ab583 commit 9596668

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

torchvision/csrc/io/image/cpu/decode_png.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ torch::Tensor decode_png(const torch::Tensor& data, ImageReadMode mode) {
7171
TORCH_CHECK(retval == 1, "Could read image metadata from content.")
7272
}
7373

74+
if (bit_depth > 8) {
75+
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
76+
TORCH_CHECK(false, "At most 8-bit PNG images are supported currently.")
77+
}
78+
7479
int channels = png_get_channels(png_ptr, info_ptr);
7580

7681
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)

0 commit comments

Comments
 (0)