PR #25946 opened by michaelni
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25946
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25946.patch


>From 2f047b1fa33df8be1d743b524503969f776221cf Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Wed, 11 Nov 2026 15:24:53 +0100
Subject: [PATCH 1/3] avcodec/jacosubdec: do not skip the terminator after \C
 and \F

Fixes: out of array read
Fixes: VpgSfZLcX6Uh

Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25134

Out of array read Replicated through API with ASAN
Read beyond the packet Replicated through UnModified FFmpeg with the ass output
---
 libavcodec/jacosubdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/jacosubdec.c b/libavcodec/jacosubdec.c
index c9fdfc2627c..58a2dd8ca55 100644
--- a/libavcodec/jacosubdec.c
+++ b/libavcodec/jacosubdec.c
@@ -53,12 +53,12 @@ static int insert_datetime(AVBPrint *dst, const char *in, 
const char *arg)
 
 static int insert_color(AVBPrint *dst, const char *in, const char *arg)
 {
-    return 1; // skip id
+    return !!*in; // skip id
 }
 
 static int insert_font(AVBPrint *dst, const char *in, const char *arg)
 {
-    return 1; // skip id
+    return !!*in; // skip id
 }
 
 static const struct {
-- 
2.54.0


>From 3484a521df4f6452a370be396b65962709141725 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Wed, 11 Nov 2026 15:24:54 +0100
Subject: [PATCH 2/3] avcodec/microdvddec: do not read the tags beyond the
 packet

The tag parser expects a 0 terminated string. ff_decode_subtitle_text()
provides one, which makes the checks against the packet end redundant.

Fixes: out of array read
Fixes: AiKrgI6Y6Kco

Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25134

Out of array read Replicated through API with ASAN
Read beyond the packet Replicated through UnModified FFmpeg with the ass output
---
 libavcodec/microdvddec.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/microdvddec.c b/libavcodec/microdvddec.c
index 4065fd02578..95f0166bf41 100644
--- a/libavcodec/microdvddec.c
+++ b/libavcodec/microdvddec.c
@@ -33,6 +33,7 @@
 #include "avcodec.h"
 #include "ass.h"
 #include "codec_internal.h"
+#include "decode.h"
 
 static int indexof(const char *s, int c)
 {
@@ -283,31 +284,32 @@ static int microdvd_decode_frame(AVCodecContext *avctx, 
AVSubtitle *sub,
                                  int *got_sub_ptr, const AVPacket *avpkt)
 {
     AVBPrint new_line;
-    char *line = avpkt->data;
-    char *end = avpkt->data + avpkt->size;
+    char *line = (char *)ff_decode_subtitle_text(avctx, avpkt);
     FFASSDecoderContext *s = avctx->priv_data;
     struct microdvd_tag tags[sizeof(MICRODVD_TAGS) - 1] = {{0}};
 
     if (avpkt->size <= 0)
         return avpkt->size;
+    if (!line)
+        return AVERROR(ENOMEM);
 
     av_bprint_init(&new_line, 0, 2048);
 
     // subtitle content
-    while (line < end && *line) {
+    while (*line) {
 
         // parse MicroDVD tags, and open them in ASS
         line = microdvd_load_tags(tags, line);
         microdvd_open_tags(&new_line, tags);
 
         // simple copy until EOL or forced carriage return
-        while (line < end && *line && *line != '|') {
+        while (*line && *line != '|') {
             av_bprint_chars(&new_line, *line, 1);
             line++;
         }
 
         // line split
-        if (line < end && *line == '|') {
+        if (*line == '|') {
             microdvd_close_no_persistent_tags(&new_line, tags);
             av_bprintf(&new_line, "\\N");
             line++;
-- 
2.54.0


>From b3fd7e34414657e768599c55b7b10fdb69147f67 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Wed, 11 Nov 2026 15:24:55 +0100
Subject: [PATCH 3/3] avcodec/microdvddec: do not read the default tags beyond
 the extradata

Fixes: out of array read
Fixes: MSrIa2a0IU4Q

Found during triage of the review of 
https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25134

Out of array read Replicated through API with ASAN
---
 libavcodec/microdvddec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavcodec/microdvddec.c b/libavcodec/microdvddec.c
index 95f0166bf41..4215f1e20b1 100644
--- a/libavcodec/microdvddec.c
+++ b/libavcodec/microdvddec.c
@@ -28,6 +28,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/avstring.h"
+#include "libavutil/mem.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/bprint.h"
 #include "avcodec.h"
@@ -342,7 +343,11 @@ static av_cold int microdvd_init(AVCodecContext *avctx)
     av_bprintf(&font_buf, "%s", ASS_DEFAULT_FONT);
 
     if (avctx->extradata) {
-        microdvd_load_tags(tags, avctx->extradata);
+        char *default_tags = av_strndup(avctx->extradata, 
avctx->extradata_size);
+
+        if (!default_tags)
+            return AVERROR(ENOMEM);
+        microdvd_load_tags(tags, default_tags);
         for (i = 0; i < sizeof(MICRODVD_TAGS) - 1; i++) {
             switch (av_tolower(tags[i].key)) {
             case 'y':
@@ -368,6 +373,7 @@ static av_cold int microdvd_init(AVCodecContext *avctx)
                 break;
             }
         }
+        av_free(default_tags);
     }
     return ff_ass_subtitle_header(avctx, font_buf.str, font_size, color,
                                   ASS_DEFAULT_BACK_COLOR, bold, italic,
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to