diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index e91d516d..5154712b 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -9337,12 +9337,12 @@ struct wuffs_png__decoder__struct { bool f_seen_srgb; bool f_seen_trns; bool f_zlib_is_dirty; + uint32_t f_chunk_type; + uint8_t f_chunk_type_array[4]; + uint32_t f_chunk_length; uint64_t f_remap_transparency; uint32_t f_dst_pixfmt; uint32_t f_src_pixfmt; - uint32_t f_chunk_type; - uint8_t f_chunk_type_array[4]; - uint64_t f_chunk_length; uint32_t f_num_animation_frames_value; uint32_t f_num_animation_loops_value; uint32_t f_num_decoded_frame_configs_value; @@ -37326,7 +37326,7 @@ wuffs_png__decoder__decode_image_config( status = wuffs_base__make_status(wuffs_base__suspension__short_read); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8); } - self->private_impl.f_chunk_length = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32))); if (self->private_impl.f_chunk_type == 1413563465) { if ( ! self->private_impl.f_seen_actl || self->private_impl.f_seen_fctl) { @@ -39369,9 +39369,9 @@ wuffs_png__decoder__decode_frame_config( while (true) { { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3); - uint64_t t_0; + uint32_t t_0; if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_0 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + t_0 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); iop_a_src += 4; } else { self->private_data.s_decode_frame_config[0].scratch = 0; @@ -39387,7 +39387,7 @@ wuffs_png__decoder__decode_frame_config( *scratch <<= 8; *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0); if (num_bits_0 == 24) { - t_0 = ((uint64_t)(*scratch >> 32)); + t_0 = ((uint32_t)(*scratch >> 32)); break; } num_bits_0 += 8; @@ -39452,7 +39452,7 @@ wuffs_png__decoder__decode_frame_config( iop_a_src += self->private_data.s_decode_frame_config[0].scratch; goto label__0__break; } - self->private_data.s_decode_frame_config[0].scratch = (self->private_impl.f_chunk_length + 4); + self->private_data.s_decode_frame_config[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9); if (self->private_data.s_decode_frame_config[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) { self->private_data.s_decode_frame_config[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src)); @@ -39545,7 +39545,7 @@ wuffs_png__decoder__skip_frame( status = wuffs_base__make_status(wuffs_base__suspension__short_read); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1); } - self->private_impl.f_chunk_length = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32))); if (self->private_impl.f_chunk_type == 1413563465) { if (self->private_impl.f_chunk_type_array[0] == 102) { @@ -39608,7 +39608,7 @@ wuffs_png__decoder__skip_frame( goto exit; } self->private_impl.f_next_animation_seq_num += 1; - self->private_data.s_skip_frame[0].scratch = (self->private_impl.f_chunk_length + 4); + self->private_data.s_skip_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 4); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4); if (self->private_data.s_skip_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) { self->private_data.s_skip_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src)); @@ -39625,7 +39625,7 @@ wuffs_png__decoder__skip_frame( status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } - self->private_data.s_skip_frame[0].scratch = (self->private_impl.f_chunk_length + 12); + self->private_data.s_skip_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); if (self->private_data.s_skip_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) { self->private_data.s_skip_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src)); @@ -39738,7 +39738,7 @@ wuffs_png__decoder__decode_frame( status = wuffs_base__make_status(wuffs_base__suspension__short_read); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2); } - self->private_impl.f_chunk_length = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + self->private_impl.f_chunk_length = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); self->private_impl.f_chunk_type = ((uint32_t)((wuffs_base__peek_u64le__no_bounds_check(iop_a_src) >> 32))); if (self->private_impl.f_chunk_type == 1413563465) { self->private_impl.f_chunk_type_array[0] = 73; @@ -39804,7 +39804,7 @@ wuffs_png__decoder__decode_frame( status = wuffs_base__make_status(wuffs_png__error__bad_chunk); goto exit; } - self->private_data.s_decode_frame[0].scratch = (self->private_impl.f_chunk_length + 12); + self->private_data.s_decode_frame[0].scratch = (((uint64_t)(self->private_impl.f_chunk_length)) + 12); WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); if (self->private_data.s_decode_frame[0].scratch > ((uint64_t)(io2_a_src - iop_a_src))) { self->private_data.s_decode_frame[0].scratch -= ((uint64_t)(io2_a_src - iop_a_src)); @@ -39980,7 +39980,7 @@ wuffs_png__decoder__decode_pass( { const uint8_t *o_1_io2_a_src = io2_a_src; wuffs_base__io_reader__limit(&io2_a_src, iop_a_src, - self->private_impl.f_chunk_length); + ((uint64_t)(self->private_impl.f_chunk_length))); if (a_src) { a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); } @@ -40001,7 +40001,7 @@ wuffs_png__decoder__decode_pass( if ( ! self->private_impl.f_ignore_checksum) { wuffs_crc32__ieee_hasher__update_u32(&self->private_data.f_crc32, wuffs_base__io__since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)), io0_a_src)); } - wuffs_base__u64__sat_sub_indirect(&self->private_impl.f_chunk_length, wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))); + wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295)))); wuffs_base__u64__sat_add_indirect(&self->private_impl.f_workbuf_wi, wuffs_base__io__count_since(v_w_mark, ((uint64_t)(iop_v_w - io0_v_w)))); io2_a_src = o_1_io2_a_src; if (a_src) { @@ -40110,9 +40110,9 @@ wuffs_png__decoder__decode_pass( } { WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5); - uint64_t t_3; + uint32_t t_3; if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= 4)) { - t_3 = ((uint64_t)(wuffs_base__peek_u32be__no_bounds_check(iop_a_src))); + t_3 = wuffs_base__peek_u32be__no_bounds_check(iop_a_src); iop_a_src += 4; } else { self->private_data.s_decode_pass[0].scratch = 0; @@ -40128,7 +40128,7 @@ wuffs_png__decoder__decode_pass( *scratch <<= 8; *scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3); if (num_bits_3 == 24) { - t_3 = ((uint64_t)(*scratch >> 32)); + t_3 = ((uint32_t)(*scratch >> 32)); break; } num_bits_3 += 8; @@ -40460,7 +40460,7 @@ wuffs_png__decoder__tell_me_more( { const uint8_t *o_0_io2_a_src = io2_a_src; wuffs_base__io_reader__limit(&io2_a_src, iop_a_src, - self->private_impl.f_chunk_length); + ((uint64_t)(self->private_impl.f_chunk_length))); if (a_src) { a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); } @@ -40475,7 +40475,7 @@ wuffs_png__decoder__tell_me_more( iop_a_src = a_src->data.ptr + a_src->meta.ri; } } - wuffs_base__u64__sat_sub_indirect(&self->private_impl.f_chunk_length, wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src)))); + wuffs_base__u32__sat_sub_indirect(&self->private_impl.f_chunk_length, ((uint32_t)((wuffs_base__io__count_since(v_r_mark, ((uint64_t)(iop_a_src - io0_a_src))) & 4294967295)))); io2_a_src = o_0_io2_a_src; if (a_src) { a_src->meta.wi = ((size_t)(io2_a_src - a_src->data.ptr)); diff --git a/std/png/decode_png.wuffs b/std/png/decode_png.wuffs index 3900cb83..d7637254 100644 --- a/std/png/decode_png.wuffs +++ b/std/png/decode_png.wuffs @@ -120,6 +120,10 @@ pub struct decoder? implements base.image_decoder( zlib_is_dirty : base.bool, + chunk_type : base.u32, + chunk_type_array : array[4] base.u8, + chunk_length : base.u32, + // remap_transparency, if non-zero, is the 32-bit or 64-bit (depending on // this.depth) argb_nonpremul color that is nominally opaque but remapped // to transparent black. @@ -134,10 +138,6 @@ pub struct decoder? implements base.image_decoder( dst_pixfmt : base.u32, src_pixfmt : base.u32, - chunk_type : base.u32, - chunk_type_array : array[4] base.u8, - chunk_length : base.u64[..= 0xFFFF_FFFF], - num_animation_frames_value : base.u32, num_animation_loops_value : base.u32, num_decoded_frame_configs_value : base.u32, @@ -270,7 +270,7 @@ pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_ yield? base."$short read" } endwhile - this.chunk_length = args.src.peek_u32be_as_u64() + this.chunk_length = args.src.peek_u32be() this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32 if this.chunk_type == 'IDAT'le { if (not this.seen_actl) or this.seen_fctl { @@ -609,7 +609,7 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) { } if this.metadata_fourcc == 0 { - args.src.skip?(n: this.chunk_length) + args.src.skip_u32?(n: this.chunk_length) } } @@ -941,7 +941,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_ } else { // Decode the next fcTL chunk. while true { - this.chunk_length = args.src.read_u32be_as_u64?() + this.chunk_length = args.src.read_u32be?() this.chunk_type = args.src.read_u32le?() if this.chunk_type == 'fdAT'le { return "#bad chunk" @@ -951,7 +951,7 @@ pub func decoder.decode_frame_config?(dst: nptr base.frame_config, src: base.io_ args.src.skip?(n: 4) // Skip the checksum. break } - args.src.skip?(n: this.chunk_length + 4) // +4 for the checksum. + args.src.skip?(n: (this.chunk_length as base.u64) + 4) // +4 for the checksum. this.chunk_length = 0 } endwhile } @@ -993,7 +993,7 @@ pri func decoder.skip_frame?(src: base.io_reader) { yield? base."$short read" } endwhile - this.chunk_length = args.src.peek_u32be_as_u64() + this.chunk_length = args.src.peek_u32be() this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32 if this.chunk_type == 'IDAT'le { @@ -1025,7 +1025,7 @@ pri func decoder.skip_frame?(src: base.io_reader) { return "#unsupported PNG file" } this.next_animation_seq_num += 1 - args.src.skip?(n: this.chunk_length + 4) // +4 for the checksum. + args.src.skip?(n: (this.chunk_length as base.u64) + 4) // +4 for the checksum. this.chunk_length = 0 continue @@ -1036,7 +1036,8 @@ pri func decoder.skip_frame?(src: base.io_reader) { return "#bad chunk" } - args.src.skip?(n: this.chunk_length + 12) // +12 for chunk length, type and checksum. + // +12 for chunk length, chunk type and checksum. + args.src.skip?(n: (this.chunk_length as base.u64) + 12) this.chunk_length = 0 } endwhile @@ -1070,7 +1071,7 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, yield? base."$short read" } endwhile - this.chunk_length = args.src.peek_u32be_as_u64() + this.chunk_length = args.src.peek_u32be() this.chunk_type = (args.src.peek_u64le() >> 32) as base.u32 if this.chunk_type == 'IDAT'le { @@ -1108,7 +1109,8 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader, return "#bad chunk" } - args.src.skip?(n: this.chunk_length + 12) // +12 for chunk length, type and checksum. + // +12 for chunk length, chunk type and checksum. + args.src.skip?(n: (this.chunk_length as base.u64) + 12) this.chunk_length = 0 } endwhile @@ -1185,7 +1187,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) { return base."#bad workbuf length" } io_bind (io: w, data: args.workbuf[this.workbuf_wi .. this.pass_workbuf_length], history_position: this.workbuf_hist_pos_base ~mod+ this.workbuf_wi) { - io_limit (io: args.src, limit: this.chunk_length) { + io_limit (io: args.src, limit: (this.chunk_length as base.u64)) { w_mark = w.mark() r_mark = args.src.mark() zlib_status =? this.zlib.transform_io?( @@ -1193,7 +1195,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) { if not this.ignore_checksum { this.crc32.update_u32!(x: args.src.since(mark: r_mark)) } - this.chunk_length ~sat-= args.src.count_since(mark: r_mark) + this.chunk_length ~sat-= (args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32 this.workbuf_wi ~sat+= w.count_since(mark: w_mark) } } @@ -1230,7 +1232,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) { } // The next chunk should be another IDAT or fdAT. - this.chunk_length = args.src.read_u32be_as_u64?() + this.chunk_length = args.src.read_u32be?() this.chunk_type = args.src.read_u32le?() if (this.chunk_type_array[0] == 'I') { if this.chunk_type <> 'IDAT'le { @@ -1357,11 +1359,11 @@ pub func decoder.tell_me_more?(dst: base.io_writer, minfo: nptr base.more_inform break } - io_limit (io: args.src, limit: this.chunk_length) { + io_limit (io: args.src, limit: this.chunk_length as base.u64) { r_mark = args.src.mark() zlib_status =? this.zlib.transform_io?( dst: args.dst, src: args.src, workbuf: this.util.empty_slice_u8()) - this.chunk_length ~sat-= args.src.count_since(mark: r_mark) + this.chunk_length ~sat-= (args.src.count_since(mark: r_mark) & 0xFFFF_FFFF) as base.u32 } if zlib_status.is_ok() {