Commit cce86fe657 for ffmpeg
commit cce86fe6573704009bb8ccc777e810b5fd2e7008
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Sat Nov 7 00:33:33 2026 +0100
avfilter/setpts: avoid undefined behavior with double to int64 cast
Fixes: inf is outside the range of representable values of type 'long'
Fixes: nw59dSqw4SNa
Found-by: Mindaugas Rukas <mindaugas@unfactorlabs.com>
This is not a security issue.
Out of range conversion Replicated through UnModified FFmpeg with UBSAN
diff --git a/libavfilter/filters.h b/libavfilter/filters.h
index 2df05a727a..4b2a5564c1 100644
--- a/libavfilter/filters.h
+++ b/libavfilter/filters.h
@@ -493,7 +493,7 @@ static inline const FFFilter *fffilter(const AVFilter *f)
#define AVFILTER_DEFINE_CLASS(fname) \
AVFILTER_DEFINE_CLASS_EXT(fname, #fname, fname##_options)
-#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
+#define D2TS(d) ((d) >= INT64_MIN && (d) < (double)INT64_MAX ? (int64_t)(d) : AV_NOPTS_VALUE)
#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts) * av_q2d(tb))
diff --git a/libavfilter/setpts.c b/libavfilter/setpts.c
index 5648a9ffae..ed176a25e7 100644
--- a/libavfilter/setpts.c
+++ b/libavfilter/setpts.c
@@ -161,7 +161,7 @@ static int config_output_video(AVFilterLink *outlink)
static inline char *double2int64str(char *buf, double v)
{
if (isnan(v)) snprintf(buf, BUF_SIZE, "nan");
- else snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)v);
+ else snprintf(buf, BUF_SIZE, "%"PRId64, D2TS(v));
return buf;
}