diff --git a/src/demux/demux.c b/src/demux/demux.c index aee28f34..b4c5ebf3 100644 --- a/src/demux/demux.c +++ b/src/demux/demux.c @@ -234,19 +234,22 @@ static ParseStatus StoreFrame(int frame_num, uint32_t min_size, case MKFOURCC('V', 'P', '8', ' '): case MKFOURCC('V', 'P', '8', 'L'): if (image_chunks == 0) { + // Extract the bitstream features, tolerating failures when the data + // is incomplete. WebPBitstreamFeatures features; - ChunkData* const image = frame->img_components_; - ++image_chunks; - image->offset_ = chunk_start_offset; - image->size_ = chunk_size; - // Extract the width and height from the bitstream, tolerating - // failures when the data is incomplete. - if ((WebPGetFeatures(mem->buf_ + image->offset_, image->size_, - &features) != VP8_STATUS_OK) && - status != PARSE_NEED_MORE_DATA) { + const VP8StatusCode vp8_status = + WebPGetFeatures(mem->buf_ + chunk_start_offset, chunk_size, + &features); + if (status == PARSE_NEED_MORE_DATA && + vp8_status == VP8_STATUS_NOT_ENOUGH_DATA) { + return PARSE_NEED_MORE_DATA; + } else if (vp8_status != VP8_STATUS_OK) { + // We have enough data, and yet WebPGetFeatures() failed. return PARSE_ERROR; } - + ++image_chunks; + frame->img_components_[0].offset_ = chunk_start_offset; + frame->img_components_[0].size_ = chunk_size; frame->width_ = features.width; frame->height_ = features.height; if (has_vp8l_alpha != NULL) *has_vp8l_alpha = features.has_alpha; diff --git a/src/webp/decode.h b/src/webp/decode.h index 40f6d693..d4eb710d 100644 --- a/src/webp/decode.h +++ b/src/webp/decode.h @@ -412,8 +412,8 @@ WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal( // Retrieve features from the bitstream. The *features structure is filled // with information gathered from the bitstream. // Returns VP8_STATUS_OK when the features are successfully retrieved. Returns -// VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieved the -// features. Returns error in other cases. +// VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the +// features from headers. Returns error in other cases. static WEBP_INLINE VP8StatusCode WebPGetFeatures( const uint8_t* data, size_t data_size, WebPBitstreamFeatures* features) {