From 293fa3120bbf1353fb7ea3674a32ec141f8ec12b Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Mon, 18 Sep 2023 16:39:46 +0200 Subject: [PATCH] [libwebp] Never send VP8_STATUS_SUSPENDED back in non-incremental. Add the incremental_ member to the internal VP8Decoder, to mimic VP8LDecoder Change-Id: I34842e473bb566f51c18fe42afda63e66c0185b6 --- media/libwebp/dec/idec_dec.c | 1 + media/libwebp/dec/vp8_dec.c | 20 ++++++++++++-------- media/libwebp/dec/vp8i_dec.h | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/media/libwebp/dec/idec_dec.c b/media/libwebp/dec/idec_dec.c index 3a592d59ed..2ae4f0a50c 100644 --- a/media/libwebp/dec/idec_dec.c +++ b/media/libwebp/dec/idec_dec.c @@ -326,6 +326,7 @@ static VP8StatusCode DecodeWebPHeaders(WebPIDecoder* const idec) { idec->is_lossless_ = headers.is_lossless; if (!idec->is_lossless_) { VP8Decoder* const dec = VP8New(); + dec->incremental_ = 1; if (dec == NULL) { return VP8_STATUS_OUT_OF_MEMORY; } diff --git a/media/libwebp/dec/vp8_dec.c b/media/libwebp/dec/vp8_dec.c index 5f51363e53..477874f604 100644 --- a/media/libwebp/dec/vp8_dec.c +++ b/media/libwebp/dec/vp8_dec.c @@ -86,6 +86,8 @@ void VP8Delete(VP8Decoder* const dec) { int VP8SetError(VP8Decoder* const dec, VP8StatusCode error, const char* const msg) { + // VP8_STATUS_SUSPENDED is only meaningful in incremental decoding. + assert(dec->incremental_ || error != VP8_STATUS_SUSPENDED); // The oldest error reported takes precedence over the new one. if (dec->status_ == VP8_STATUS_OK) { dec->status_ = error; @@ -190,12 +192,12 @@ static int ParseSegmentHeader(VP8BitReader* br, } // Paragraph 9.5 -// This function returns VP8_STATUS_SUSPENDED if we don't have all the -// necessary data in 'buf'. -// This case is not necessarily an error (for incremental decoding). -// Still, no bitreader is ever initialized to make it possible to read -// unavailable memory. -// If we don't even have the partitions' sizes, than VP8_STATUS_NOT_ENOUGH_DATA +// If we don't have all the necessary data in 'buf', this function returns +// VP8_STATUS_SUSPENDED in incremental decoding, VP8_STATUS_NOT_ENOUGH_DATA +// otherwise. +// In incremental decoding, this case is not necessarily an error. Still, no +// bitreader is ever initialized to make it possible to read unavailable memory. +// If we don't even have the partitions' sizes, then VP8_STATUS_NOT_ENOUGH_DATA // is returned, and this is an unrecoverable error. // If the partitions were positioned ok, VP8_STATUS_OK is returned. static VP8StatusCode ParsePartitions(VP8Decoder* const dec, @@ -225,8 +227,10 @@ static VP8StatusCode ParsePartitions(VP8Decoder* const dec, sz += 3; } VP8InitBitReader(dec->parts_ + last_part, part_start, size_left); - return (part_start < buf_end) ? VP8_STATUS_OK : - VP8_STATUS_SUSPENDED; // Init is ok, but there's not enough data + if (part_start < buf_end) return VP8_STATUS_OK; + return dec->incremental_ + ? VP8_STATUS_SUSPENDED // Init is ok, but there's not enough data + : VP8_STATUS_NOT_ENOUGH_DATA; } // Paragraph 9.4 diff --git a/media/libwebp/dec/vp8i_dec.h b/media/libwebp/dec/vp8i_dec.h index 31d9080ca1..364896318c 100644 --- a/media/libwebp/dec/vp8i_dec.h +++ b/media/libwebp/dec/vp8i_dec.h @@ -186,6 +186,7 @@ struct VP8Decoder { // Main data source VP8BitReader br_; + int incremental_; // if true, incremental decoding is expected // headers VP8FrameHeader frm_hdr_;