Disallow re-use of same transformation.

Limit the overall number of transformations to 4 and disallow any
duplicate transform for decoding an image.

Change-Id: Ic4b0ecd553db96702e117fd073617237d95e45c0
This commit is contained in:
Vikas Arora 2012-05-23 16:09:53 +05:30
parent 98ec717f1e
commit 9fc64edc21
2 changed files with 10 additions and 3 deletions

View File

@ -707,15 +707,22 @@ static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
static int ReadTransform(int* const xsize, int const* ysize, static int ReadTransform(int* const xsize, int const* ysize,
VP8LDecoder* const dec) { VP8LDecoder* const dec) {
int i;
int ok = 1; int ok = 1;
VP8LBitReader* const br = &dec->br_; VP8LBitReader* const br = &dec->br_;
VP8LTransform* transform = &dec->transforms_[dec->next_transform_]; VP8LTransform* transform = &dec->transforms_[dec->next_transform_];
const VP8LImageTransformType type = const VP8LImageTransformType type =
(VP8LImageTransformType)VP8LReadBits(br, 2); (VP8LImageTransformType)VP8LReadBits(br, 2);
if (dec->next_transform_ == NUM_TRANSFORMS) { // Each transform type can only be present once in the stream.
return 0; // TODO(later): use a bit set to mark already-used transforms.
for (i = 0; i < dec->next_transform_; ++i) {
if (dec->transforms_[i].type_ == type) {
return 0; // Already there, let's not accept the second same transform.
}
} }
assert(dec->next_transform_ < NUM_TRANSFORMS);
transform->type_ = type; transform->type_ = type;
transform->xsize_ = *xsize; transform->xsize_ = *xsize;
transform->ysize_ = *ysize; transform->ysize_ = *ysize;

View File

@ -23,7 +23,7 @@
extern "C" { extern "C" {
#endif #endif
#define NUM_TRANSFORMS 8 #define NUM_TRANSFORMS 4
#define HUFFMAN_CODES_PER_META_CODE 5 #define HUFFMAN_CODES_PER_META_CODE 5
#define ARGB_BLACK 0xff000000 #define ARGB_BLACK 0xff000000
#define NUM_LITERAL_CODES 256 #define NUM_LITERAL_CODES 256