Detect canvas and image size mismatch in decoder.
Will probably have to be re-visited when FRGM are switched on. Change-Id: I51c15e4c3887ab8f04d92ec783deca274cd09f41
This commit is contained in:
parent
30c8158a53
commit
f626fe2e9f
@ -286,6 +286,10 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
|||||||
int* const has_alpha,
|
int* const has_alpha,
|
||||||
int* const has_animation,
|
int* const has_animation,
|
||||||
WebPHeaderStructure* const headers) {
|
WebPHeaderStructure* const headers) {
|
||||||
|
int canvas_width = 0;
|
||||||
|
int canvas_height = 0;
|
||||||
|
int image_width = 0;
|
||||||
|
int image_height = 0;
|
||||||
int found_riff = 0;
|
int found_riff = 0;
|
||||||
int found_vp8x = 0;
|
int found_vp8x = 0;
|
||||||
VP8StatusCode status;
|
VP8StatusCode status;
|
||||||
@ -308,19 +312,25 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
|||||||
// Skip over VP8X.
|
// Skip over VP8X.
|
||||||
{
|
{
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
status = ParseVP8X(&data, &data_size, &found_vp8x, width, height, &flags);
|
int animation_present;
|
||||||
|
status = ParseVP8X(&data, &data_size, &found_vp8x,
|
||||||
|
&canvas_width, &canvas_height, &flags);
|
||||||
if (status != VP8_STATUS_OK) {
|
if (status != VP8_STATUS_OK) {
|
||||||
return status; // Wrong VP8X / insufficient data.
|
return status; // Wrong VP8X / insufficient data.
|
||||||
}
|
}
|
||||||
|
animation_present = !!(flags & ANIMATION_FLAG);
|
||||||
if (!found_riff && found_vp8x) {
|
if (!found_riff && found_vp8x) {
|
||||||
// Note: This restriction may be removed in the future, if it becomes
|
// Note: This restriction may be removed in the future, if it becomes
|
||||||
// necessary to send VP8X chunk to the decoder.
|
// necessary to send VP8X chunk to the decoder.
|
||||||
return VP8_STATUS_BITSTREAM_ERROR;
|
return VP8_STATUS_BITSTREAM_ERROR;
|
||||||
}
|
}
|
||||||
if (has_alpha != NULL) *has_alpha = !!(flags & ALPHA_FLAG);
|
if (has_alpha != NULL) *has_alpha = !!(flags & ALPHA_FLAG);
|
||||||
if (has_animation != NULL) *has_animation = !!(flags & ANIMATION_FLAG);
|
if (has_animation != NULL) *has_animation = animation_present;
|
||||||
if (found_vp8x && headers == NULL) {
|
|
||||||
return VP8_STATUS_OK; // Return features from VP8X header.
|
if (found_vp8x && animation_present && headers == NULL) {
|
||||||
|
if (width != NULL) *width = canvas_width;
|
||||||
|
if (height != NULL) *height = canvas_height;
|
||||||
|
return VP8_STATUS_OK; // Just return features from VP8X header.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,8 +361,8 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
|||||||
return VP8_STATUS_NOT_ENOUGH_DATA;
|
return VP8_STATUS_NOT_ENOUGH_DATA;
|
||||||
}
|
}
|
||||||
// Validates raw VP8 data.
|
// Validates raw VP8 data.
|
||||||
if (!VP8GetInfo(data, data_size,
|
if (!VP8GetInfo(data, data_size, (uint32_t)hdrs.compressed_size,
|
||||||
(uint32_t)hdrs.compressed_size, width, height)) {
|
&image_width, &image_height)) {
|
||||||
return VP8_STATUS_BITSTREAM_ERROR;
|
return VP8_STATUS_BITSTREAM_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -360,11 +370,18 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
|||||||
return VP8_STATUS_NOT_ENOUGH_DATA;
|
return VP8_STATUS_NOT_ENOUGH_DATA;
|
||||||
}
|
}
|
||||||
// Validates raw VP8L data.
|
// Validates raw VP8L data.
|
||||||
if (!VP8LGetInfo(data, data_size, width, height, has_alpha)) {
|
if (!VP8LGetInfo(data, data_size, &image_width, &image_height, has_alpha)) {
|
||||||
return VP8_STATUS_BITSTREAM_ERROR;
|
return VP8_STATUS_BITSTREAM_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Validates image size coherency. TODO(urvang): what about FRGM?
|
||||||
|
if (found_vp8x) {
|
||||||
|
if (canvas_width != image_width || canvas_height != image_height) {
|
||||||
|
return VP8_STATUS_BITSTREAM_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (width != NULL) *width = image_width;
|
||||||
|
if (height != NULL) *height = image_height;
|
||||||
if (has_alpha != NULL) {
|
if (has_alpha != NULL) {
|
||||||
// If the data did not contain a VP8X/VP8L chunk the only definitive way
|
// If the data did not contain a VP8X/VP8L chunk the only definitive way
|
||||||
// to set this is by looking for alpha data (from an ALPH chunk).
|
// to set this is by looking for alpha data (from an ALPH chunk).
|
||||||
|
Loading…
Reference in New Issue
Block a user