Re: [FFmpeg-devel] [PATCH] tests/checkasm/llauddsp: Avoid UB integer overflow

2024-05-15 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> The only multiplicators used in scalarproduct_and_madd_*
> are -1, 0 and +1. Yet it is of type int and the checkasm
> test uses the complete range of int for it, leading to overflows
> that don't happen for actual users.
> 
> Fix this by using a more reasonable range for mul: Given
> that it is used in v1[i] += v3[i] * mul with v1 being
> a 16bit integer, it makes no sense to use values for mul
> that don't fit into 16bit.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  tests/checkasm/llauddsp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/checkasm/llauddsp.c b/tests/checkasm/llauddsp.c
> index e6eab589b2..969166baca 100644
> --- a/tests/checkasm/llauddsp.c
> +++ b/tests/checkasm/llauddsp.c
> @@ -49,7 +49,7 @@ static void 
> check_scalarproduct_and_madd_int16(LLAudDSPContext *c)
>  randomize_buf(v1, BUF_SIZE);
>  randomize_buf(v2, BUF_SIZE);
>  randomize_buf(v3, BUF_SIZE);
> -mul = rnd();
> +mul = (int16_t)rnd();
>  
>  if (check_func(c->scalarproduct_and_madd_int16,
> "scalarproduct_and_madd_int16")) {
> @@ -84,7 +84,7 @@ static void 
> check_scalarproduct_and_madd_int32(LLAudDSPContext *c)
>  randomize_buf(v1, BUF_SIZE);
>  randomize_buf(v2, BUF_SIZE);
>  randomize_buf(v3, BUF_SIZE);
> -mul = rnd();
> +mul = (int16_t)rnd();
>  
>  if (check_func(c->scalarproduct_and_madd_int32,
> "scalarproduct_and_madd_int32")) {

Will apply tonight unless there are objections.

- Andreas

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] tests/checkasm/llauddsp: Avoid UB integer overflow

2024-05-12 Thread Andreas Rheinhardt
The only multiplicators used in scalarproduct_and_madd_*
are -1, 0 and +1. Yet it is of type int and the checkasm
test uses the complete range of int for it, leading to overflows
that don't happen for actual users.

Fix this by using a more reasonable range for mul: Given
that it is used in v1[i] += v3[i] * mul with v1 being
a 16bit integer, it makes no sense to use values for mul
that don't fit into 16bit.

Signed-off-by: Andreas Rheinhardt 
---
 tests/checkasm/llauddsp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/checkasm/llauddsp.c b/tests/checkasm/llauddsp.c
index e6eab589b2..969166baca 100644
--- a/tests/checkasm/llauddsp.c
+++ b/tests/checkasm/llauddsp.c
@@ -49,7 +49,7 @@ static void 
check_scalarproduct_and_madd_int16(LLAudDSPContext *c)
 randomize_buf(v1, BUF_SIZE);
 randomize_buf(v2, BUF_SIZE);
 randomize_buf(v3, BUF_SIZE);
-mul = rnd();
+mul = (int16_t)rnd();
 
 if (check_func(c->scalarproduct_and_madd_int16,
"scalarproduct_and_madd_int16")) {
@@ -84,7 +84,7 @@ static void 
check_scalarproduct_and_madd_int32(LLAudDSPContext *c)
 randomize_buf(v1, BUF_SIZE);
 randomize_buf(v2, BUF_SIZE);
 randomize_buf(v3, BUF_SIZE);
-mul = rnd();
+mul = (int16_t)rnd();
 
 if (check_func(c->scalarproduct_and_madd_int32,
"scalarproduct_and_madd_int32")) {
-- 
2.40.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".