Have std/png decode_frame handle multiple IDATs

This commit is contained in:
Nigel Tao committed 2020-12-25 15:40:24 +11:00
1 parent 43a74d6b81
commit 6980e93a76
2 files changed
+97 -2

No files matched your search

+14 -1
View File
@@ -15,9 +15,12 @@
use "std/crc32"
use "std/zlib"
pub status "#bad chunk"
pub status "#bad header"
pub status "#unsupported PNG file"
pri status "#internal error: zlib decoder did not exhaust its input"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
pub struct decoder? implements base.image_decoder(
@@ -266,7 +269,17 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
} else if zlib_status <> base."$short read" {
return zlib_status
} else if this.chunk_length == 0 {
// TODO: move to the next IDAT.
// TODO: verify CRC-32 checksum.
args.src.skip_u32?(n: 4)
// The next chunk should be another IDAT.
this.chunk_length = args.src.read_u32be_as_u64?()
this.chunk_type = args.src.read_u32le?()
if this.chunk_type <> 'IDAT'le {
return "#bad chunk"
}
continue
} else if args.src.length() > 0 {
return "#internal error: zlib decoder did not exhaust its input"
}
yield? base."$short read"
} endwhile