mirror of
https://github.com/jellyfin/jellyfin-ffmpeg.git
synced 2026-09-03 05:09:58 +03:00
New upstream version 3.5~git20180113
This commit is contained in:
@@ -949,6 +949,7 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
|
||||
Jpeg2000Cblk *cblk = prec->cblk + cblkno;
|
||||
int incl, newpasses, llen;
|
||||
void *tmp;
|
||||
|
||||
if (cblk->npasses)
|
||||
incl = get_bits(s, 1);
|
||||
@@ -988,6 +989,14 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
|
||||
cblk->nb_lengthinc = 0;
|
||||
cblk->nb_terminationsinc = 0;
|
||||
av_free(cblk->lengthinc);
|
||||
cblk->lengthinc = av_mallocz_array(newpasses , sizeof(*cblk->lengthinc));
|
||||
if (!cblk->lengthinc)
|
||||
return AVERROR(ENOMEM);
|
||||
tmp = av_realloc_array(cblk->data_start, cblk->nb_terminations + newpasses + 1, sizeof(*cblk->data_start));
|
||||
if (!tmp)
|
||||
return AVERROR(ENOMEM);
|
||||
cblk->data_start = tmp;
|
||||
do {
|
||||
int newpasses1 = 0;
|
||||
|
||||
@@ -1001,10 +1010,18 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
|
||||
if ((ret = get_bits(s, av_log2(newpasses1) + cblk->lblock)) < 0)
|
||||
return ret;
|
||||
if (ret > sizeof(cblk->data)) {
|
||||
if (ret > cblk->data_allocated) {
|
||||
size_t new_size = FFMAX(2*cblk->data_allocated, ret);
|
||||
void *new = av_realloc(cblk->data, new_size);
|
||||
if (new) {
|
||||
cblk->data = new;
|
||||
cblk->data_allocated = new_size;
|
||||
}
|
||||
}
|
||||
if (ret > cblk->data_allocated) {
|
||||
avpriv_request_sample(s->avctx,
|
||||
"Block with lengthinc greater than %"SIZE_SPECIFIER"",
|
||||
sizeof(cblk->data));
|
||||
cblk->data_allocated);
|
||||
return AVERROR_PATCHWELCOME;
|
||||
}
|
||||
cblk->lengthinc[cblk->nb_lengthinc++] = ret;
|
||||
@@ -1029,9 +1046,19 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
nb_code_blocks = prec->nb_codeblocks_height * prec->nb_codeblocks_width;
|
||||
for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
|
||||
Jpeg2000Cblk *cblk = prec->cblk + cblkno;
|
||||
if (!cblk->nb_terminationsinc && !cblk->lengthinc)
|
||||
continue;
|
||||
for (cwsno = 0; cwsno < cblk->nb_lengthinc; cwsno ++) {
|
||||
if (cblk->data_allocated < cblk->length + cblk->lengthinc[cwsno] + 4) {
|
||||
size_t new_size = FFMAX(2*cblk->data_allocated, cblk->length + cblk->lengthinc[cwsno] + 4);
|
||||
void *new = av_realloc(cblk->data, new_size);
|
||||
if (new) {
|
||||
cblk->data = new;
|
||||
cblk->data_allocated = new_size;
|
||||
}
|
||||
}
|
||||
if ( bytestream2_get_bytes_left(&s->g) < cblk->lengthinc[cwsno]
|
||||
|| sizeof(cblk->data) < cblk->length + cblk->lengthinc[cwsno] + 4
|
||||
|| cblk->data_allocated < cblk->length + cblk->lengthinc[cwsno] + 4
|
||||
) {
|
||||
av_log(s->avctx, AV_LOG_ERROR,
|
||||
"Block length %"PRIu16" or lengthinc %d is too large, left %d\n",
|
||||
@@ -1050,6 +1077,7 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
|
||||
cblk->data_start[cblk->nb_terminations] = cblk->length;
|
||||
}
|
||||
}
|
||||
av_freep(&cblk->lengthinc);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -1981,7 +2009,16 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
|
||||
bytestream2_get_bytes_left(&s->g) >= 8) {
|
||||
atom_size = bytestream2_get_be32u(&s->g);
|
||||
atom = bytestream2_get_be32u(&s->g);
|
||||
atom_end = bytestream2_tell(&s->g) + atom_size - 8;
|
||||
if (atom_size == 1) {
|
||||
if (bytestream2_get_be32u(&s->g)) {
|
||||
avpriv_request_sample(s->avctx, "Huge atom");
|
||||
return 0;
|
||||
}
|
||||
atom_size = bytestream2_get_be32u(&s->g);
|
||||
atom_end = bytestream2_tell(&s->g) + atom_size - 16;
|
||||
} else {
|
||||
atom_end = bytestream2_tell(&s->g) + atom_size - 8;
|
||||
}
|
||||
|
||||
if (atom == JP2_CODESTREAM)
|
||||
return 1;
|
||||
@@ -2039,13 +2076,13 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s)
|
||||
}
|
||||
if (colour_depth[1] <= 8) {
|
||||
g = bytestream2_get_byteu(&s->g) << 8 - colour_depth[1];
|
||||
r |= r >> colour_depth[1];
|
||||
g |= g >> colour_depth[1];
|
||||
} else {
|
||||
g = bytestream2_get_be16u(&s->g) >> colour_depth[1] - 8;
|
||||
}
|
||||
if (colour_depth[2] <= 8) {
|
||||
b = bytestream2_get_byteu(&s->g) << 8 - colour_depth[2];
|
||||
r |= r >> colour_depth[2];
|
||||
b |= b >> colour_depth[2];
|
||||
} else {
|
||||
b = bytestream2_get_be16u(&s->g) >> colour_depth[2] - 8;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user