PR #22599 opened by Priyanshuthapliyal
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22599
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22599.patch

The expression abs(ctx->raw_samples[c][i]) invokes undefined behavior
when raw_samples[c][i] == INT_MIN. Per libavutil/common.h, FFABS()
shares the same INT_MIN UB as abs(). FFABSU() is the correct
replacement as it casts to unsigned before negation.

Reported-by: Guanni Qu <[email protected]>
Signed-off-by: Priyanshu Thapliyal <[email protected]>


>From 8894db1ed395eaa3ccb3d4c3aaa6fd309552e756 Mon Sep 17 00:00:00 2001
From: Priyanshu Thapliyal <[email protected]>
Date: Tue, 24 Mar 2026 13:57:27 +0530
Subject: [PATCH] avcodec/alsdec: fix abs(INT_MIN) UB in read_diff_float_data()

Replace abs() with FFABSU() to avoid undefined behavior when
raw_samples[c][i] == INT_MIN. Per libavutil/common.h, FFABS()
has the same INT_MIN UB as abs(); FFABSU() is the correct
helper as it casts to unsigned before negation.

Reported-by: Guanni Qu <[email protected]>
Signed-off-by: Priyanshu Thapliyal <[email protected]>
---
 libavcodec/alsdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index 09c1b8db9e..e91ff57b03 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -1560,7 +1560,7 @@ static int read_diff_float_data(ALSDecContext *ctx, 
unsigned int ra_frame) {
                 if (ctx->raw_samples[c][i] != 0) {
                     //The following logic is taken from Table 14.45 and 14.46 
from the ISO spec
                     if (av_cmp_sf_ieee754(acf[c], FLOAT_1)) {
-                        nbits[i] = 23 - av_log2(abs(ctx->raw_samples[c][i]));
+                        nbits[i] = 23 - 
av_log2(FFABSU(ctx->raw_samples[c][i]));
                     } else {
                         nbits[i] = 23;
                     }
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to