diff mbox series

[FFmpeg-devel,2/2] avcodec/jpeg2000dec: fix tilepart processing

Message ID 20240615031517.148911-2-owatanab@es.takushoku-u.ac.jp
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/jpeg2000dec: Add support for placeholder passes, CAP, and CPF markers | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

WATANABE Osamu June 15, 2024, 3:15 a.m. UTC
This is the same as https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240607002549.2259139-1-owatanab@es.takushoku-u.ac.jp/

Signed-off-by: Osamu Watanabe <owatanab@es.takushoku-u.ac.jp>
---
 libavcodec/jpeg2000dec.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index d299c67cc7..395cf34bcd 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1097,6 +1097,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;
         }
@@ -1106,10 +1107,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) {