Commit f0358dc1 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '278a923c'

* commit '278a923c':
  jpeg2000: Validate SIZ parsing

Conflicts:
	libavcodec/jpeg2000dec.c

This commit is not exactly merged due to bugs in it
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 2e85737b 278a923c
...@@ -73,7 +73,7 @@ typedef struct Jpeg2000DecoderContext { ...@@ -73,7 +73,7 @@ typedef struct Jpeg2000DecoderContext {
int precision; int precision;
int ncomponents; int ncomponents;
int tile_width, tile_height; int tile_width, tile_height;
int numXtiles, numYtiles; unsigned numXtiles, numYtiles;
int maxtilelen; int maxtilelen;
Jpeg2000CodingStyle codsty[4]; Jpeg2000CodingStyle codsty[4];
...@@ -176,14 +176,25 @@ static int get_siz(Jpeg2000DecoderContext *s) ...@@ -176,14 +176,25 @@ static int get_siz(Jpeg2000DecoderContext *s)
s->tile_offset_y = bytestream2_get_be32u(&s->g); // YT0Siz s->tile_offset_y = bytestream2_get_be32u(&s->g); // YT0Siz
ncomponents = bytestream2_get_be16u(&s->g); // CSiz ncomponents = bytestream2_get_be16u(&s->g); // CSiz
if (ncomponents <= 0 || ncomponents > 4) { if (ncomponents <= 0) {
av_log(s->avctx, AV_LOG_ERROR, "unsupported/invalid ncomponents: %d\n", ncomponents); av_log(s->avctx, AV_LOG_ERROR, "Invalid number of components: %d\n",
s->ncomponents);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (ncomponents > 4) {
avpriv_request_sample(s->avctx, "Support for %d components",
s->ncomponents);
return AVERROR_PATCHWELCOME;
}
s->ncomponents = ncomponents; s->ncomponents = ncomponents;
if (s->tile_width<=0 || s->tile_height<=0) if (s->tile_width <= 0 || s->tile_height <= 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid tile dimension %dx%d.\n",
s->tile_width, s->tile_height);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
if (bytestream2_get_bytes_left(&s->g) < 3 * s->ncomponents) if (bytestream2_get_bytes_left(&s->g) < 3 * s->ncomponents)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -196,7 +207,9 @@ static int get_siz(Jpeg2000DecoderContext *s) ...@@ -196,7 +207,9 @@ static int get_siz(Jpeg2000DecoderContext *s)
s->cdx[i] = bytestream2_get_byteu(&s->g); s->cdx[i] = bytestream2_get_byteu(&s->g);
s->cdy[i] = bytestream2_get_byteu(&s->g); s->cdy[i] = bytestream2_get_byteu(&s->g);
if (s->cdx[i] != 1 || s->cdy[i] != 1) { if (s->cdx[i] != 1 || s->cdy[i] != 1) {
av_log(s->avctx, AV_LOG_ERROR, "unsupported/ CDxy values %d %d for component %d\n", s->cdx[i], s->cdy[i], i); avpriv_request_sample(s->avctx,
"CDxy values %d %d for component %d",
s->cdx[i], s->cdy[i], i);
if (!s->cdx[i] || !s->cdy[i]) if (!s->cdx[i] || !s->cdy[i])
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -205,12 +218,16 @@ static int get_siz(Jpeg2000DecoderContext *s) ...@@ -205,12 +218,16 @@ static int get_siz(Jpeg2000DecoderContext *s)
s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width); s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width);
s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height); s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height);
if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(Jpeg2000Tile)) if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(*s->tile)) {
s->numXtiles = s->numYtiles = 0;
return AVERROR(EINVAL); return AVERROR(EINVAL);
}
s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(*s->tile)); s->tile = av_mallocz_array(s->numXtiles * s->numYtiles, sizeof(*s->tile));
if (!s->tile) if (!s->tile) {
s->numXtiles = s->numYtiles = 0;
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
}
for (i = 0; i < s->numXtiles * s->numYtiles; i++) { for (i = 0; i < s->numXtiles * s->numYtiles; i++) {
Jpeg2000Tile *tile = s->tile + i; Jpeg2000Tile *tile = s->tile + i;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment