Tweak std/png decode_other_chunk if-else chain

This commit is contained in:
Nigel Tao committed 2021-11-09 09:05:11 +11:00
1 parent 74c1dfce96
commit e847766b02
2 files changed
+100 -84

No files matched your search

+72 -64
View File
@@ -37790,74 +37790,82 @@ wuffs_png__decoder__decode_other_chunk(
goto suspend; goto suspend;
} }
self->private_impl.f_seen_plte = true; self->private_impl.f_seen_plte = true;
} else if ((self->private_impl.f_chunk_type == 1297238115) && self->private_impl.f_report_metadata_chrm) { } else if (self->private_impl.f_chunk_type == 1297238115) {
if (self->private_impl.f_seen_chrm) { if (self->private_impl.f_report_metadata_chrm) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk); if (self->private_impl.f_seen_chrm) {
goto exit; status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_png__decoder__decode_chrm(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_chrm = true;
} }
if (a_src) { } else if (self->private_impl.f_chunk_type == 1095582055) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr)); if (self->private_impl.f_report_metadata_gama) {
if (self->private_impl.f_seen_gama) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_png__decoder__decode_gama(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_gama = true;
} }
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2); } else if (self->private_impl.f_chunk_type == 1346585449) {
status = wuffs_png__decoder__decode_chrm(self, a_src); if (self->private_impl.f_report_metadata_iccp) {
if (a_src) { if (self->private_impl.f_seen_iccp) {
iop_a_src = a_src->data.ptr + a_src->meta.ri; status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_png__decoder__decode_iccp(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_iccp = true;
} }
if (status.repr) { } else if (self->private_impl.f_chunk_type == 1111970419) {
goto suspend; if (self->private_impl.f_report_metadata_srgb) {
if (self->private_impl.f_seen_srgb) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
status = wuffs_png__decoder__decode_srgb(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_srgb = true;
} }
self->private_impl.f_seen_chrm = true;
} else if ((self->private_impl.f_chunk_type == 1095582055) && self->private_impl.f_report_metadata_gama) {
if (self->private_impl.f_seen_gama) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_png__decoder__decode_gama(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_gama = true;
} else if ((self->private_impl.f_chunk_type == 1346585449) && self->private_impl.f_report_metadata_iccp) {
if (self->private_impl.f_seen_iccp) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_png__decoder__decode_iccp(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_iccp = true;
} else if ((self->private_impl.f_chunk_type == 1111970419) && self->private_impl.f_report_metadata_srgb) {
if (self->private_impl.f_seen_srgb) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
goto exit;
}
if (a_src) {
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
status = wuffs_png__decoder__decode_srgb(self, a_src);
if (a_src) {
iop_a_src = a_src->data.ptr + a_src->meta.ri;
}
if (status.repr) {
goto suspend;
}
self->private_impl.f_seen_srgb = true;
} else if (self->private_impl.f_chunk_type == 1397641844) { } else if (self->private_impl.f_chunk_type == 1397641844) {
if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) { if (self->private_impl.f_seen_trns || (self->private_impl.f_color_type > 3) || ((self->private_impl.f_color_type == 3) && ! self->private_impl.f_seen_plte)) {
status = wuffs_base__make_status(wuffs_png__error__bad_chunk); status = wuffs_base__make_status(wuffs_png__error__bad_chunk);
+28 -20
View File
@@ -452,33 +452,41 @@ pri func decoder.decode_other_chunk?(src: base.io_reader) {
this.decode_plte?(src: args.src) this.decode_plte?(src: args.src)
this.seen_plte = true this.seen_plte = true
} else if (this.chunk_type == 'cHRM'le) and this.report_metadata_chrm { } else if this.chunk_type == 'cHRM'le {
if this.seen_chrm { if this.report_metadata_chrm {
return "#bad chunk" if this.seen_chrm {
return "#bad chunk"
}
this.decode_chrm?(src: args.src)
this.seen_chrm = true
} }
this.decode_chrm?(src: args.src)
this.seen_chrm = true
} else if (this.chunk_type == 'gAMA'le) and this.report_metadata_gama { } else if this.chunk_type == 'gAMA'le {
if this.seen_gama { if this.report_metadata_gama {
return "#bad chunk" if this.seen_gama {
return "#bad chunk"
}
this.decode_gama?(src: args.src)
this.seen_gama = true
} }
this.decode_gama?(src: args.src)
this.seen_gama = true
} else if (this.chunk_type == 'iCCP'le) and this.report_metadata_iccp { } else if this.chunk_type == 'iCCP'le {
if this.seen_iccp { if this.report_metadata_iccp {
return "#bad chunk" if this.seen_iccp {
return "#bad chunk"
}
this.decode_iccp?(src: args.src)
this.seen_iccp = true
} }
this.decode_iccp?(src: args.src)
this.seen_iccp = true
} else if (this.chunk_type == 'sRGB'le) and this.report_metadata_srgb { } else if this.chunk_type == 'sRGB'le {
if this.seen_srgb { if this.report_metadata_srgb {
return "#bad chunk" if this.seen_srgb {
return "#bad chunk"
}
this.decode_srgb?(src: args.src)
this.seen_srgb = true
} }
this.decode_srgb?(src: args.src)
this.seen_srgb = true
} else if this.chunk_type == 'tRNS'le { } else if this.chunk_type == 'tRNS'le {
if this.seen_trns or (this.color_type > 3) or if this.seen_trns or (this.color_type > 3) or