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

This restricts what we can parse to what we can also allocate later



>From 0b7e80494eeefe7cfab10ce7c3e6669f517dc6ff Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Mon, 28 Sep 2026 23:46:27 +0200
Subject: [PATCH] avutil/parseutils: reject sizes that cannot be a picture in
 av_parse_video_size()

This restricts what we can parse to what we can also allocate later
---
 libavutil/parseutils.c | 4 ++++
 libavutil/parseutils.h | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 9f57b16ec2..1083756804 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -27,6 +27,7 @@
 #include "avutil.h"
 #include "common.h"
 #include "eval.h"
+#include "imgutils.h"
 #include "log.h"
 #include "random_seed.h"
 #include "time_internal.h"
@@ -173,6 +174,9 @@ int av_parse_video_size(int *width_ptr, int *height_ptr, 
const char *str)
     }
     if (width <= 0 || height <= 0)
         return AVERROR(EINVAL);
+    int ret = av_image_check_size2(width, height, INT64_MAX, AV_PIX_FMT_NONE, 
0, NULL);
+    if (ret < 0)
+        return ret;
     *width_ptr  = width;
     *height_ptr = height;
     return 0;
diff --git a/libavutil/parseutils.h b/libavutil/parseutils.h
index dad5c2775b..5db8298f1e 100644
--- a/libavutil/parseutils.h
+++ b/libavutil/parseutils.h
@@ -61,7 +61,8 @@ int av_parse_ratio(AVRational *q, const char *str, int max,
  * height value
  * @param[in] str the string to parse: it has to be a string in the format
  * width x height or a valid video size abbreviation.
- * @return >= 0 on success, a negative error code otherwise
+ * @return >= 0 on success, a negative error code otherwise, also when
+ * the size is not a valid picture size according to av_image_check_size2()
  */
 int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str);
 
-- 
2.52.0

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

Reply via email to