Have std/png partially decode invalid images

This commit is contained in:
Nigel Tao committed 2022-01-25 14:36:31 +11:00
1 parent a4b14a0f17
commit 5ecd84e0ed
2 files changed
+16 -10

No files matched your search

+6 -4
View File
@@ -40549,13 +40549,15 @@ wuffs_png__decoder__decode_frame(
} }
if (wuffs_base__status__is_ok(&v_status)) { if (wuffs_base__status__is_ok(&v_status)) {
goto label__1__break; goto label__1__break;
} else if ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed)) { } else if (wuffs_base__status__is_error(&v_status) || ((v_status.repr == wuffs_base__suspension__short_read) && (a_src && a_src->meta.closed))) {
if (self->private_impl.f_workbuf_wi <= ((uint64_t)(a_workbuf.len))) { if (self->private_impl.f_workbuf_wi <= ((uint64_t)(a_workbuf.len))) {
wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi)); wuffs_png__decoder__filter_and_swizzle(self, a_dst, wuffs_base__slice_u8__subslice_j(a_workbuf, self->private_impl.f_workbuf_wi));
} }
while (true) { if (v_status.repr == wuffs_base__suspension__short_read) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read); while (true) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
}
} }
} }
status = v_status; status = v_status;
+10 -6
View File
@@ -1199,18 +1199,22 @@ pub func decoder.decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reader,
status =? this.decode_pass?(src: args.src, workbuf: args.workbuf) status =? this.decode_pass?(src: args.src, workbuf: args.workbuf)
if status.is_ok() { if status.is_ok() {
break break
} else if (status == base."$short read") and args.src.is_closed() { } else if status.is_error() or
// The input was truncated. Produce whatever pixels we can ((status == base."$short read") and args.src.is_closed()) {
// and then generate "$short read" forever. // The input was truncated or invalid. Produce whatever
// pixels we can and then, if truncated, generate "$short
// read" forever.
if this.workbuf_wi <= args.workbuf.length() { if this.workbuf_wi <= args.workbuf.length() {
// This might return "#internal error: inconsistent // This might return "#internal error: inconsistent
// workbuf length" because of the ".. this.workbuf_wi". // workbuf length" because of the ".. this.workbuf_wi".
// We just ignore the error. // We just ignore the error.
this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi]) this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf[.. this.workbuf_wi])
} }
while true { if status == base."$short read" {
yield? base."$short read" while true {
} endwhile yield? base."$short read"
} endwhile
}
} }
yield? status yield? status
} endwhile } endwhile