From: michaelni via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: michaelni <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avutil/eval: Check depth of AVExpr (PR #22286)
Date: Thu, 26 Feb 2026 00:23:49 -0000
Message-ID: <177206542987.25.13269513663935286216@29965ddac10e> (raw)
PR #22286 opened by michaelni
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22286
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22286.patch
we already check the depth of the parser but the AVExpr tree differs
Fixes: stack exhaustion
Fixes: YWH-PGM40646-39
Found-by: jpraveenrao
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>From b9313d585f0377ca84da050aa99a5801b172944a Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michael@niedermayer.cc>
Date: Thu, 26 Feb 2026 00:36:42 +0100
Subject: [PATCH] avutil/eval: Check depth of AVExpr
we already check the depth of the parser but the AVExpr tree differs
Fixes: stack exhaustion
Fixes: YWH-PGM40646-39
Found-by: jpraveenrao
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavutil/eval.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 8069ed88a2..c40b381aae 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -40,6 +40,8 @@
#include "avstring.h"
#include "reverse.h"
+#define MAX_DEPTH 100
+
typedef struct Parser {
const AVClass *class;
int stack_index;
@@ -176,6 +178,7 @@ struct AVExpr {
struct AVExpr *param[3];
double *var;
FFSFC64 *prng_state;
+ int depth;
};
static double etime(double v)
@@ -430,13 +433,16 @@ static int parse_primary(AVExpr **e, Parser *p)
av_expr_free(d);
return ret;
}
+ d->depth = FFMAX(d->depth, d->param[0]->depth+1);
if (p->s[0]== ',') {
p->s++; // ","
parse_expr(&d->param[1], p);
+ d->depth = FFMAX(d->depth, d->param[1]->depth+1);
}
if (p->s[0]== ',') {
p->s++; // ","
parse_expr(&d->param[2], p);
+ d->depth = FFMAX(d->depth, d->param[2]->depth+1);
}
if (p->s[0] != ')') {
av_log(p, AV_LOG_ERROR, "Missing ')' or too many args in '%s'\n", s0);
@@ -529,6 +535,9 @@ static int parse_primary(AVExpr **e, Parser *p)
static AVExpr *make_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1)
{
+ int depth = FFMAX(p0->depth, p1->depth) + 1;
+ if (depth > MAX_DEPTH)
+ return NULL;
AVExpr *e = av_mallocz(sizeof(AVExpr));
if (!e)
return NULL;
@@ -536,6 +545,7 @@ static AVExpr *make_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1)
e->value =value ;
e->param[0] =p0 ;
e->param[1] =p1 ;
+ e->depth = depth;
return e;
}
--
2.52.0
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2026-02-26 0:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=177206542987.25.13269513663935286216@29965ddac10e \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git