make VP8Init() handle short buffers (< 2 bytes) correctly

Change-Id: Ie354a97f0dc44d95bd5fad92851a76cfdedae3de
This commit is contained in:
Pascal Massimino 2010-12-20 05:45:49 -08:00
parent b1c9e8b48c
commit 280c36583f
3 changed files with 13 additions and 16 deletions

View File

@ -18,17 +18,16 @@ extern "C" {
//-----------------------------------------------------------------------------
// VP8BitReader
int VP8Init(VP8BitReader* const br, const uint8_t* buf, uint32_t size) {
if (!br || !buf || size < 2) {
return 0;
}
br->buf_ = buf + 2;
br->buf_end_ = buf + size;
br->left_ = -8;
br->value_ = (buf[0] << 8) | buf[1];
void VP8Init(VP8BitReader* const br, const uint8_t* buf, uint32_t size) {
assert(br);
assert(buf);
br->range_ = 255 - 1;
br->eof_ = 0;
return 1;
br->buf_ = buf;
br->buf_end_ = buf + size;
// Need two initial bytes.
br->value_ = (VP8GetByte(br) << 8) | VP8GetByte(br);
br->left_ = -8;
}
const uint8_t kVP8Log2Range[128] = {

View File

@ -33,8 +33,8 @@ typedef struct {
int left_; // how many unused bits (negated)
} VP8BitReader;
// Initialize the bit reader and the boolean decoder. Return true if ok.
int VP8Init(VP8BitReader* const br, const uint8_t* buf, uint32_t size);
// Initialize the bit reader and the boolean decoder.
void VP8Init(VP8BitReader* const br, const uint8_t* buf, uint32_t size);
// return the next value made of 'num_bits' bits
uint32_t VP8GetValue(VP8BitReader* const br, int num_bits);

View File

@ -188,13 +188,13 @@ int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
return 0;
}
SetOk(dec);
if (io == NULL || io->data == NULL || io->data_size <= 4) {
if (io == NULL) {
return VP8SetError(dec, 2, "null VP8Io passed to VP8GetHeaders()");
}
buf = (uint8_t *)io->data;
buf_size = io->data_size;
if (buf_size < 4) {
if (buf == NULL || buf_size <= 4) {
return VP8SetError(dec, 2, "Not enough data to parse frame header");
}
@ -259,9 +259,7 @@ int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
}
br = &dec->br_;
if (!VP8Init(br, buf, buf_size)) {
return VP8SetError(dec, 2, "not enough data for bit reader");
}
VP8Init(br, buf, buf_size);
if (frm_hdr->partition_length_ > buf_size) {
return VP8SetError(dec, 2, "bad partition length");
}