PR #25901 opened by Marti2203
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25901
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25901.patch
With `ascale=log` and `hmode=sign`, `get_log_bin_sign()` returns `w / 2 + w / 2
= w` for an even width when a positive sample is at or above full scale. The
histograms have `w` entries per channel, so `filter_frame()` then reads and
writes one element past their end (`achistogram[bin]++` / `shistogram[bin]++`).
Reproduce on an ASan build:
ffmpeg -f lavfi -i
"sine=frequency=100:duration=0.2,volume=8:precision=float" \
-filter_complex
"[0:a]aformat=sample_fmts=flt,ahistogram=ascale=log:hmode=sign" -f null -
gives a heap-buffer-overflow in `filter_frame()` (`avf_ahistogram.c:282`). A
full-scale s32 input does the same without any gain, since `INT32_MAX` becomes
1.0f after the conversion to float.
The patch clips the bin to `w - 1`, the largest bin the other `get_bin`
functions return. Only the bins that were out of range change: with the patch
both inputs above run without an ASan report, and for `volume` 0.5, 7.6 and 7.9
(peaks below 1.0) the framemd5 of `ascale=log:hmode=sign`,
`ascale=log:hmode=abs` and `ascale=lin:hmode=sign` is the same before and after.
This issue was found by an LLM-Enhanced Static Analysis Engine and verified
manually.
>From 85cbdcd4abaec6b841f3a1f3ca825f59c5adc98d Mon Sep 17 00:00:00 2001
From: Martin Mirchev <[email protected]>
Date: Tue, 10 Nov 2026 12:06:39 +0800
Subject: [PATCH] avfilter/avf_ahistogram: keep the log sign bin inside the
histogram
With ascale=log and hmode=sign, get_log_bin_sign() returns
w / 2 + w / 2 = w for an even width when a positive sample is at or
above full scale, e.g. a float sample of 1.0 or more, or INT32_MAX in
an s32 input after the conversion to float. The histograms only have
w entries per channel, so filter_frame() then reads and writes one
element past their end.
Clip the bin to w - 1, the largest bin the other get_bin functions
return.
Signed-off-by: Martin Mirchev <[email protected]>
---
libavfilter/avf_ahistogram.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavfilter/avf_ahistogram.c b/libavfilter/avf_ahistogram.c
index 33f0e68db0c..56f9fe135a7 100644
--- a/libavfilter/avf_ahistogram.c
+++ b/libavfilter/avf_ahistogram.c
@@ -147,7 +147,9 @@ static int get_log_bin_abs(float in, int w)
static int get_log_bin_sign(float in, int w)
{
- return (w / 2) + FFSIGN(in) * lrintf(av_clipf(1.f + log10f(fabsf(in)) /
6.f, 0.f, 1.f) * (w / 2));
+ int bin = (w / 2) + FFSIGN(in) * lrintf(av_clipf(1.f + log10f(fabsf(in)) /
6.f, 0.f, 1.f) * (w / 2));
+
+ return FFMIN(bin, w - 1);
}
static int config_output(AVFilterLink *outlink)
--
2.54.0
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]