improve VP8L signature detection by checking the version bits too

Change-Id: I20bea00b9582d7ea8c7b643616c78f717ce1bdf2
This commit is contained in:
skal 2013-09-27 18:17:23 +02:00
parent 5cd43e4316
commit 92d47e4ca9

View File

@ -84,20 +84,19 @@ static int DecodeImageStream(int xsize, int ysize,
//------------------------------------------------------------------------------
int VP8LCheckSignature(const uint8_t* const data, size_t size) {
return (size >= 1) && (data[0] == VP8L_MAGIC_BYTE);
return (size >= VP8L_FRAME_HEADER_SIZE &&
data[0] == VP8L_MAGIC_BYTE &&
(data[4] >> 5) == 0); // version
}
static int ReadImageInfo(VP8LBitReader* const br,
int* const width, int* const height,
int* const has_alpha) {
const uint8_t signature = VP8LReadBits(br, 8);
if (!VP8LCheckSignature(&signature, 1)) {
return 0;
}
if (VP8LReadBits(br, 8) != VP8L_MAGIC_BYTE) return 0;
*width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
*height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
*has_alpha = VP8LReadBits(br, 1);
VP8LReadBits(br, VP8L_VERSION_BITS); // Read/ignore the version number.
if (VP8LReadBits(br, VP8L_VERSION_BITS) != 0) return 0;
return 1;
}
@ -105,6 +104,8 @@ int VP8LGetInfo(const uint8_t* data, size_t data_size,
int* const width, int* const height, int* const has_alpha) {
if (data == NULL || data_size < VP8L_FRAME_HEADER_SIZE) {
return 0; // not enough data
} else if (!VP8LCheckSignature(data, data_size)) {
return 0; // bad signature
} else {
int w, h, a;
VP8LBitReader br;