avcodec/jpeg2000dec: fix tilepart processing

Fix http://trac.ffmpeg.org/ticket/10121

Signed-off-by: Pierre-Anthony Lemieux <pal@palemieux.com>
This commit is contained in:
Osamu Watanabe 2024-06-07 09:25:49 +09:00 committed by Pierre-Anthony Lemieux
parent c75940db29
commit 6f4a95cfb8
No known key found for this signature in database
GPG Key ID: 698FA1F0F8D4EED4
1 changed files with 10 additions and 1 deletions

View File

@ -1005,6 +1005,7 @@ static inline void select_header(Jpeg2000DecoderContext *s, const Jpeg2000Tile *
{
s->g = tile->tile_part[*tp_index].header_tpg;
if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
av_log(s->avctx, AV_LOG_WARNING, "Packet header bytes in PPM marker segment is too short.\n");
if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
s->g = tile->tile_part[++(*tp_index)].tpg;
}
@ -1014,10 +1015,18 @@ static inline void select_header(Jpeg2000DecoderContext *s, const Jpeg2000Tile *
static inline void select_stream(Jpeg2000DecoderContext *s, const Jpeg2000Tile *tile,
int *tp_index, const Jpeg2000CodingStyle *codsty)
{
int32_t is_endof_tp;
s->g = tile->tile_part[*tp_index].tpg;
if (bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8) {
is_endof_tp = bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8;
// Following while loop is necessary because a tilepart may include only SOD marker.
// Such a tilepart has neither packet header nor compressed data.
while (is_endof_tp) {
if (*tp_index < FF_ARRAY_ELEMS(tile->tile_part) - 1) {
s->g = tile->tile_part[++(*tp_index)].tpg;
is_endof_tp = bytestream2_get_bytes_left(&s->g) == 0 && s->bit_index == 8;
} else {
is_endof_tp = 0;
}
}
if (codsty->csty & JPEG2000_CSTY_SOP) {