avcodec/osq: Switch back to av_ceil_log2()
authorMichael Niedermayer <[email protected]>
Tue, 17 Jun 2025 00:31:28 +0000 (02:31 +0200)
committerMichael Niedermayer <[email protected]>
Mon, 4 Aug 2025 16:51:35 +0000 (18:51 +0200)
This returns to code closer to prior 56c334d732dbbce43b0c8fc0809ec545b7946832
The prior fixes should limit the sum and avoid the need for double argument log2()

Fixes: Assertion n>=0 && n<=32 failed at libavcodec/get_bits.h:406
Fixes: 410109093/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-6550900028276736

No testcases except fuzzers

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <[email protected]>
(cherry picked from commit a5f861d335491ce2350102b74c7a17f875cad0ed)
Signed-off-by: Michael Niedermayer <[email protected]>
libavcodec/osq.c

index 7cbb36d5d618076ed50c42bf302bafd1ee7f9565..949348e4d2475e2e2198d6ba6fe95e8c3aba7482 100644 (file)
@@ -164,7 +164,8 @@ static int update_residue_parameter(OSQChannel *cb)
     if (!sum)
         return 0;
     x = sum / cb->count;
-    rice_k = ceil(log2(x));
+    av_assert2(x <= 0x80000000U);
+    rice_k = av_ceil_log2(x);
     if (rice_k >= 30) {
         double f = floor(sum / 1.4426952 + 0.5);
         if (f <= 1) {