diff --git a/src/dec/vp8l.c b/src/dec/vp8l.c index e0922134..ac433a5a 100644 --- a/src/dec/vp8l.c +++ b/src/dec/vp8l.c @@ -291,7 +291,7 @@ static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec, code_lengths); } - ok = ok && !br->error_; + ok = ok && !br->eos_; if (!ok) { dec->status_ = VP8_STATUS_BITSTREAM_ERROR; return 0; @@ -336,7 +336,7 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize, } } - if (br->error_) goto Error; + if (br->eos_) goto Error; // Find maximum alphabet size for the htree group. for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) { @@ -948,14 +948,12 @@ static int DecodeAlphaData(VP8LDecoder* const dec, uint8_t* const data, goto End; } assert(br->eos_ == VP8LIsEndOfStream(br)); - ok = !br->error_; - if (!ok) goto End; } // Process the remaining rows corresponding to last row-block. ExtractPalettedAlphaRows(dec, row); End: - if (br->error_ || !ok || (br->eos_ && pos < end)) { + if (!ok || (br->eos_ && pos < end)) { ok = 0; dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED : VP8_STATUS_BITSTREAM_ERROR; @@ -1068,14 +1066,12 @@ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data, goto End; } assert(br->eos_ == VP8LIsEndOfStream(br)); - ok = !br->error_; - if (!ok) goto End; } // Process the remaining rows corresponding to last row-block. if (process_func != NULL) process_func(dec, row); End: - if (br->error_ || !ok || (br->eos_ && src < src_end)) { + if (!ok || (br->eos_ && src < src_end)) { ok = 0; dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED : VP8_STATUS_BITSTREAM_ERROR; @@ -1310,17 +1306,17 @@ static int DecodeImageStream(int xsize, int ysize, // Use the Huffman trees to decode the LZ77 encoded data. ok = DecodeImageData(dec, data, transform_xsize, transform_ysize, transform_ysize, NULL); - ok = ok && !br->error_; + ok = ok && !br->eos_; End: - if (!ok) { WebPSafeFree(data); ClearMetadata(hdr); - // If not enough data (br.eos_) resulted in BIT_STREAM_ERROR, update the - // status appropriately. - if (dec->status_ == VP8_STATUS_BITSTREAM_ERROR && dec->br_.eos_) { - dec->status_ = VP8_STATUS_SUSPENDED; + // Check status coherency. + if (dec->br_.eos_) { + assert(dec->status_ == VP8_STATUS_SUSPENDED); + } else { + assert(dec->status_ == VP8_STATUS_BITSTREAM_ERROR); } } else { if (decoded_data != NULL) { diff --git a/src/utils/bit_reader.c b/src/utils/bit_reader.c index 64503e6b..23e68471 100644 --- a/src/utils/bit_reader.c +++ b/src/utils/bit_reader.c @@ -136,7 +136,6 @@ void VP8LInitBitReader(VP8LBitReader* const br, const uint8_t* const start, br->val_ = 0; br->bit_pos_ = 0; br->eos_ = 0; - br->error_ = 0; if (length > sizeof(br->val_)) { length = sizeof(br->val_); @@ -157,8 +156,7 @@ void VP8LBitReaderSetBuffer(VP8LBitReader* const br, br->buf_ = buf; br->len_ = len; // pos_ > len_ should be considered a param error. - br->error_ = (br->pos_ > br->len_); - br->eos_ = br->error_ || VP8LIsEndOfStream(br); + br->eos_ = (br->pos_ > br->len_) || VP8LIsEndOfStream(br); } // If not at EOS, reload up to VP8L_LBITS byte-by-byte @@ -202,7 +200,7 @@ uint32_t VP8LReadBits(VP8LBitReader* const br, int n_bits) { ShiftBytes(br); return val; } else { - br->error_ = 1; + br->eos_ = 1; return 0; } } diff --git a/src/utils/bit_reader.h b/src/utils/bit_reader.h index 89b5cc1c..f9f4c3be 100644 --- a/src/utils/bit_reader.h +++ b/src/utils/bit_reader.h @@ -118,8 +118,7 @@ typedef struct { size_t len_; // buffer length size_t pos_; // byte position in buf_ int bit_pos_; // current bit-reading position in val_ - int eos_; // bitstream is finished - int error_; // an error occurred (buffer overflow attempt...) + int eos_; // true if a bit was read past the end of buffer } VP8LBitReader; void VP8LInitBitReader(VP8LBitReader* const br,