Commit 1d47c3c6c9 for ffmpeg

commit 1d47c3c6c9a47b7203fd9a31640255bb5ac8a5c5
Author: Martin Mirchev <mmirchev@comp.nus.edu.sg>
Date:   Tue Nov 10 12:08:24 2026 +0800

    avfilter/vf_midequalizer: clip out-of-depth samples to the histogram

    For formats with more than 8 bits, the histograms and the contrast
    change table have 1 << depth entries, but compute_histogram16() and
    midequalizer16() index them with the raw 16-bit sample. A sample with
    bits set above the depth, e.g. from a gray9le rawvideo input with
    arbitrary words, reads and writes far past the 512-entry histogram.

    Clip the sample to the last entry before using it as an index.

    Signed-off-by: Martin Mirchev <mmirchev@comp.nus.edu.sg>

diff --git a/libavfilter/vf_midequalizer.c b/libavfilter/vf_midequalizer.c
index 9720cefdf2..1035f1b56e 100644
--- a/libavfilter/vf_midequalizer.c
+++ b/libavfilter/vf_midequalizer.c
@@ -157,7 +157,7 @@ static void compute_histogram16(const uint16_t *src, ptrdiff_t linesize,

     for (y = 0; y < h; y++) {
         for (x = 0; x < w; x++) {
-            histogram[src[x]] += 1;
+            histogram[FFMIN(src[x], (unsigned)hsize - 1)] += 1;
         }
         src += linesize;
     }
@@ -230,7 +230,7 @@ static void midequalizer16(const uint8_t *in0, const uint8_t *in1,

     for (y = 0; y < h0; y++) {
         for (x = 0; x < w0; x++) {
-            d[x] = cchange[i[x]];
+            d[x] = cchange[FFMIN(i[x], (unsigned)hsize - 1)];
         }
         d += dlinesize / 2;
         i += linesize1 / 2;