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


>From c6ac360ac15b8853ccbd20ef3f19b331d1532fff Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 16 Apr 2026 16:26:59 +0200
Subject: [PATCH 1/5] avcodec/pdvenc: Remove always-false pixel format check

Already checked via CODEC_PIXFMTS.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/pdvenc.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/libavcodec/pdvenc.c b/libavcodec/pdvenc.c
index fbd7138e6d..80f8599f51 100644
--- a/libavcodec/pdvenc.c
+++ b/libavcodec/pdvenc.c
@@ -47,11 +47,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     size_t frame_size;
     int ret;
 
-    if (avctx->pix_fmt != AV_PIX_FMT_MONOBLACK) {
-        av_log(avctx, AV_LOG_ERROR, "Only monob pixel format is supported.\n");
-        return AVERROR(EINVAL);
-    }
-
     ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
     if (ret < 0)
         return ret;
-- 
2.52.0


>From 34c770f4f35d3d239c8174e5307199d437f8388d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 16 Apr 2026 16:29:44 +0200
Subject: [PATCH 2/5] avcodec/pdvenc: Remove always false check

av_image_check_size() already checks that width*height
fits into an int.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/pdvenc.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/libavcodec/pdvenc.c b/libavcodec/pdvenc.c
index 80f8599f51..8334824067 100644
--- a/libavcodec/pdvenc.c
+++ b/libavcodec/pdvenc.c
@@ -44,7 +44,6 @@ typedef struct PDVEncContext {
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     PDVEncContext *s = avctx->priv_data;
-    size_t frame_size;
     int ret;
 
     ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
@@ -53,14 +52,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     s->row_size   = (avctx->width + 7) >> 3;
 
-    ret = av_size_mult(s->row_size, avctx->height, &frame_size);
-    if (ret < 0 || frame_size > INT_MAX) {
-        av_log(avctx, AV_LOG_ERROR,
-               "Cannot allocate frame buffer for dimensions %dx%d.\n",
-               avctx->width, avctx->height);
-        return AVERROR(EINVAL);
-    }
-    s->frame_size = frame_size;
+    s->frame_size = s->row_size * avctx->height;
 
     s->previous_frame = av_malloc(s->frame_size);
     s->work_frame     = av_malloc(s->frame_size);
-- 
2.52.0


>From 33a47c1452be83b048e75b613ddab92cf3709ab5 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 16 Apr 2026 16:43:30 +0200
Subject: [PATCH 3/5] avcodec/pdvenc: Return directly upon error

This encoder has the FF_CODEC_CAP_INIT_CLEANUP cap set.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/pdvenc.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/libavcodec/pdvenc.c b/libavcodec/pdvenc.c
index 8334824067..af844623a9 100644
--- a/libavcodec/pdvenc.c
+++ b/libavcodec/pdvenc.c
@@ -57,24 +57,15 @@ static av_cold int encode_init(AVCodecContext *avctx)
     s->previous_frame = av_malloc(s->frame_size);
     s->work_frame     = av_malloc(s->frame_size);
     if (!s->previous_frame || !s->work_frame)
-        goto fail;
+        return AVERROR(ENOMEM);
 
     avctx->bits_per_coded_sample = 1;
 
-    ret = ff_deflate_init(&s->zstream,
-                          avctx->compression_level == FF_COMPRESSION_DEFAULT ?
-                          Z_DEFAULT_COMPRESSION :
-                          av_clip(avctx->compression_level, 0, 9),
-                          avctx);
-    if (ret < 0)
-        goto fail;
-
-    return 0;
-
-fail:
-    av_freep(&s->work_frame);
-    av_freep(&s->previous_frame);
-    return ret < 0 ? ret : AVERROR(ENOMEM);
+    return ff_deflate_init(&s->zstream,
+                           avctx->compression_level == FF_COMPRESSION_DEFAULT ?
+                           Z_DEFAULT_COMPRESSION :
+                           av_clip(avctx->compression_level, 0, 9),
+                           avctx);
 }
 
 static av_cold int encode_end(AVCodecContext *avctx)
-- 
2.52.0


>From d6fcae490f50447e51dda95b96c50e5b29d7958e Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 16 Apr 2026 16:51:59 +0200
Subject: [PATCH 4/5] avformat/pdvenc: Remove always-false checks

The number of streams is always one (namely one video stream
with codec id AV_CODEC_ID_PDV) due to the MAX_ONE_OF_EACH,
ONLY_DEFAULT_CODECS flags. Also, the generic code (init_muxer()
in mux.c) checks that video streams have proper dimensions set.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/pdvenc.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/libavformat/pdvenc.c b/libavformat/pdvenc.c
index 72fc611acc..324c2dfb8a 100644
--- a/libavformat/pdvenc.c
+++ b/libavformat/pdvenc.c
@@ -80,17 +80,8 @@ static int pdv_write_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (s->nb_streams != 1) {
-        av_log(s, AV_LOG_ERROR, "PDV muxer supports exactly one stream.\n");
-        return AVERROR(EINVAL);
-    }
-
     st = s->streams[0];
 
-    if (st->codecpar->width <= 0 || st->codecpar->height <= 0) {
-        av_log(s, AV_LOG_ERROR, "Invalid output dimensions.\n");
-        return AVERROR(EINVAL);
-    }
     if (st->codecpar->width > UINT16_MAX || st->codecpar->height > UINT16_MAX) 
{
         av_log(s, AV_LOG_ERROR, "Output dimensions exceed PDV limits.\n");
         return AVERROR(EINVAL);
-- 
2.52.0


>From be1ee0cb37cc32f24e59976bd5a3d74d9d0acfb4 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Thu, 16 Apr 2026 16:55:06 +0200
Subject: [PATCH 5/5] avformat/pdvenc: Don't silently truncate value

This muxer seems to intend to support output that does
not begin at zero (instead of e.g. just hardcoding
nb_frames_pos to 16). But then it is possible
that avio_seek() returns values > INT_MAX even
though the part of the file written by us can not
exceed this value. So the return value of avio_seek()
needs to be checked as 64bit integer and not silently
truncated to int.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/pdvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/pdvenc.c b/libavformat/pdvenc.c
index 324c2dfb8a..4f70fd3ad8 100644
--- a/libavformat/pdvenc.c
+++ b/libavformat/pdvenc.c
@@ -158,7 +158,7 @@ static int pdv_write_trailer(AVFormatContext *s)
     PDVMuxContext *pdv = s->priv_data;
     int64_t payload_size = avio_tell(s->pb);
     const uint32_t table_gap = 4U * (pdv->max_frames - pdv->nb_frames);
-    int ret;
+    int64_t ret;
 
     if (payload_size < 0)
         return AVERROR(EIO);
-- 
2.52.0

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

Reply via email to