Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/2 v2] checkasm/flacdsp: sanitize lpc arguments
Date: Sat, 11 May 2024 17:31:20 -0300
Message-ID: <20240511203120.1723-1-jamrial@gmail.com> (raw)
In-Reply-To: <20240511194656.1576-2-jamrial@gmail.com>

Fixes signed integer overflows as reported by ubsan.

Signed-off-by: James Almer <jamrial@gmail.com>
---
Now allowing negative values.

 tests/checkasm/flacdsp.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tests/checkasm/flacdsp.c b/tests/checkasm/flacdsp.c
index 6561b4ed20..d694c1093b 100644
--- a/tests/checkasm/flacdsp.c
+++ b/tests/checkasm/flacdsp.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include "checkasm.h"
 #include "libavcodec/flacdsp.h"
+#include "libavcodec/mathops.h"
 #include "libavutil/common.h"
 #include "libavutil/internal.h"
 #include "libavutil/intreadwrite.h"
@@ -54,9 +55,10 @@ static void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **ne
     bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
 }
 
-static void check_lpc(int pred_order)
+static void check_lpc(int pred_order, int bps)
 {
     int qlevel = rnd() % 16;
+    int coeff_prec = (rnd() % 15) + 1;
     LOCAL_ALIGNED_16(int32_t, coeffs, [32]);
     LOCAL_ALIGNED_16(int32_t, dst,  [BUF_SIZE]);
     LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]);
@@ -64,10 +66,13 @@ static void check_lpc(int pred_order)
 
     declare_func(void, int32_t *, const int[32], int, int, int);
 
+    if (bps <= 16)
+        coeff_prec = av_clip(coeff_prec, 0, 32 - bps - av_log2(pred_order));
+
     for (int i = 0; i < 32; i++)
-        coeffs[i] = rnd();
+        coeffs[i] = sign_extend(rnd(), coeff_prec);
     for (int i = 0; i < BUF_SIZE; i++)
-        dst[i] = rnd();
+        dst[i] = sign_extend(rnd(), bps);
 
     memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
     memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
@@ -116,10 +121,10 @@ void checkasm_check_flacdsp(void)
 
     for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
         if (check_func(h.lpc16, "flac_lpc_16_%d", pred_orders[i]))
-            check_lpc(pred_orders[i]);
+            check_lpc(pred_orders[i], 16);
     for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
         if (check_func(h.lpc32, "flac_lpc_32_%d", pred_orders[i]))
-            check_lpc(pred_orders[i]);
+            check_lpc(pred_orders[i], 32);
 
     report("lpc");
 }
-- 
2.45.0

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

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

  reply	other threads:[~2024-05-11 20:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11 19:46 [FFmpeg-devel] [PATCH 1/2] checkasm/flacdsp: run lpc benchmarks with an unmodified buffer James Almer
2024-05-11 19:46 ` [FFmpeg-devel] [PATCH 2/2] checkasm/flacdsp: sanitize lpc arguments James Almer
2024-05-11 20:31   ` James Almer [this message]
2024-05-12 16:06 ` [FFmpeg-devel] [PATCH 3/8] x86/flacdsp: add a SSE4 version of lpc16 James Almer
2024-05-12 16:06 ` [FFmpeg-devel] [PATCH 4/8] avcodec/flacdsp: split off wasted bit handling into dsp functions James Almer
2024-05-12 16:15   ` Andreas Rheinhardt
2024-05-12 16:44     ` James Almer
2024-05-12 16:06 ` [FFmpeg-devel] [PATCH 5/8] checkasm/flacdsp: add a test for wasted32 James Almer
2024-05-12 16:38   ` Rémi Denis-Courmont
2024-05-12 16:42     ` [FFmpeg-devel] [PATCH 5/8 v2] " James Almer
2024-05-12 16:06 ` [FFmpeg-devel] [PATCH 6/8] x86/flacdsp: add a SSE2 version of wasted32 James Almer
2024-05-12 18:51   ` [FFmpeg-devel] [PATCH 6/8 v2] " James Almer
2024-05-12 20:22     ` Lynne via ffmpeg-devel
2024-05-12 16:06 ` [FFmpeg-devel] [PATCH 7/8] checkasm/flacdsp: add a test for wasted33 James Almer
2024-05-12 16:06 ` [FFmpeg-devel] [PATCH 8/8] x86/flacdsp: add SSE4 and AVX2 versions of wasted33 James Almer
2024-05-12 18:53   ` [FFmpeg-devel] [PATCH 8/8 v2] x86/flacdsp: add an SSE4 version " James Almer
2024-05-12 20:36 ` [FFmpeg-devel] [PATCH 09/10] avcodec/flacdsp: split off lpc33 into a dsp function James Almer
2024-05-12 20:36 ` [FFmpeg-devel] [PATCH 10/10] checkasm/flacdsp: add a test for lpc33 James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240511203120.1723-1-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git