std: limit supported image dimensions to 0xFF_FFFF

This commit is contained in:
Nigel Tao committed 2023-04-16 08:57:55 +10:00
1 parent d8c23a3a66
commit e126c998e0
10 files changed
+175 -123

No files matched your search

+6 -8
View File
@@ -16,8 +16,6 @@ use "std/crc32"
use "std/zlib"
pub struct decoder? implements base.image_decoder(
// The 0x00FF_FFFF limit is arbitrary (the PNG spec says 0x7FFF_FFFF) but
// it means that (width * height * bytes_per_pixel) doesn't overflow a u64.
width : base.u32[..= 0x00FF_FFFF],
height : base.u32[..= 0x00FF_FFFF],
@@ -336,18 +334,18 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
var a8 : base.u8
a32 = args.src.read_u32be?()
if (a32 == 0) or (a32 >= 0x8000_0000) {
if (a32 == 0) or (a32 > 0x7FFF_FFFF) {
return "#bad header"
} else if a32 >= 0x0100_0000 {
return "#unsupported PNG file"
} else if a32 > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.width = a32
a32 = args.src.read_u32be?()
if (a32 == 0) or (a32 >= 0x8000_0000) {
if (a32 == 0) or (a32 > 0x7FFF_FFFF) {
return "#bad header"
} else if a32 >= 0x0100_0000 {
return "#unsupported PNG file"
} else if a32 > 0xFF_FFFF {
return base."#unsupported image dimension"
}
this.height = a32