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
+10 -4

No files matched your search

+3 -1
View File
@@ -40549,15 +40549,17 @@ 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));
} }
if (v_status.repr == wuffs_base__suspension__short_read) {
while (true) { while (true) {
status = wuffs_base__make_status(wuffs_base__suspension__short_read); status = wuffs_base__make_status(wuffs_base__suspension__short_read);
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
} }
} }
}
status = v_status; status = v_status;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7); WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(7);
} }
+7 -3
View File
@@ -1199,19 +1199,23 @@ 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])
} }
if status == base."$short read" {
while true { while true {
yield? base."$short read" yield? base."$short read"
} endwhile } endwhile
} }
}
yield? status yield? status
} endwhile } endwhile
status = this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf) status = this.filter_and_swizzle!(dst: args.dst, workbuf: args.workbuf)