* [FFmpeg-devel] [PATCH] tests/checkasm/svq1enc: Use proper range for input
@ 2024-05-06 15:41 Andreas Rheinhardt
2024-05-08 19:27 ` Andreas Rheinhardt
2024-05-13 8:40 ` Tomas Härdin
0 siblings, 2 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2024-05-06 15:41 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
ssd_int8_vs_int16 is only called from encode_block()
in svq1enc.c; it calls it in stages: At stage 0,
the int16_t array contains the difference of two
uint16_t. At each of the following stages, the
int16_t array is filled by subtracting an int8_t from
the current stage's int16_t array. The maximum stage
is five, so the int16_t are in the range
(-255 + 5 * 127)..(255 + 5 * 128).
This commit modifies the checkasm test to only use
values from this range, fixing (undefined) integer overflow
in the test.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
tests/checkasm/svq1enc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tests/checkasm/svq1enc.c b/tests/checkasm/svq1enc.c
index 1a6f531141..f9abdcbff8 100644
--- a/tests/checkasm/svq1enc.c
+++ b/tests/checkasm/svq1enc.c
@@ -18,7 +18,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/svq1encdsp.h"
@@ -26,11 +25,13 @@
#include "checkasm.h"
#define BUF_SIZE 1024
+#define MIN_VAL (-255 - 5 * 127)
+#define MAX_VAL ( 255 + 5 * 128)
#define randomize(buf, len) \
do { \
for (int i = 0; i < len; i++) \
- buf[i] = ((rnd() % 65281) - 32641); \
+ buf[i] = ((rnd() % (MAX_VAL - MIN_VAL + 1)) + MIN_VAL); \
} while (0)
static void test_ssd_int8_vs_int16(SVQ1EncDSPContext *s) {
--
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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] tests/checkasm/svq1enc: Use proper range for input
2024-05-06 15:41 [FFmpeg-devel] [PATCH] tests/checkasm/svq1enc: Use proper range for input Andreas Rheinhardt
@ 2024-05-08 19:27 ` Andreas Rheinhardt
2024-05-13 8:40 ` Tomas Härdin
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2024-05-08 19:27 UTC (permalink / raw)
To: ffmpeg-devel
Andreas Rheinhardt:
> ssd_int8_vs_int16 is only called from encode_block()
> in svq1enc.c; it calls it in stages: At stage 0,
> the int16_t array contains the difference of two
> uint16_t. At each of the following stages, the
> int16_t array is filled by subtracting an int8_t from
> the current stage's int16_t array. The maximum stage
> is five, so the int16_t are in the range
> (-255 + 5 * 127)..(255 + 5 * 128).
>
> This commit modifies the checkasm test to only use
> values from this range, fixing (undefined) integer overflow
> in the test.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> tests/checkasm/svq1enc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tests/checkasm/svq1enc.c b/tests/checkasm/svq1enc.c
> index 1a6f531141..f9abdcbff8 100644
> --- a/tests/checkasm/svq1enc.c
> +++ b/tests/checkasm/svq1enc.c
> @@ -18,7 +18,6 @@
> * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> */
>
> -#include "libavutil/mem.h"
> #include "libavutil/mem_internal.h"
>
> #include "libavcodec/svq1encdsp.h"
> @@ -26,11 +25,13 @@
> #include "checkasm.h"
>
> #define BUF_SIZE 1024
> +#define MIN_VAL (-255 - 5 * 127)
> +#define MAX_VAL ( 255 + 5 * 128)
>
> #define randomize(buf, len) \
> do { \
> for (int i = 0; i < len; i++) \
> - buf[i] = ((rnd() % 65281) - 32641); \
> + buf[i] = ((rnd() % (MAX_VAL - MIN_VAL + 1)) + MIN_VAL); \
> } while (0)
>
> static void test_ssd_int8_vs_int16(SVQ1EncDSPContext *s) {
Will apply tomorrow 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-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] tests/checkasm/svq1enc: Use proper range for input
2024-05-06 15:41 [FFmpeg-devel] [PATCH] tests/checkasm/svq1enc: Use proper range for input Andreas Rheinhardt
2024-05-08 19:27 ` Andreas Rheinhardt
@ 2024-05-13 8:40 ` Tomas Härdin
1 sibling, 0 replies; 3+ messages in thread
From: Tomas Härdin @ 2024-05-13 8:40 UTC (permalink / raw)
To: FFmpeg development discussions and patches
mån 2024-05-06 klockan 17:41 +0200 skrev Andreas Rheinhardt:
> ssd_int8_vs_int16 is only called from encode_block()
> in svq1enc.c; it calls it in stages: At stage 0,
> the int16_t array contains the difference of two
> uint16_t. At each of the following stages, the
> int16_t array is filled by subtracting an int8_t from
> the current stage's int16_t array. The maximum stage
> is five, so the int16_t are in the range
> (-255 + 5 * 127)..(255 + 5 * 128).
>
> This commit modifies the checkasm test to only use
> values from this range, fixing (undefined) integer overflow
> in the test.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> tests/checkasm/svq1enc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tests/checkasm/svq1enc.c b/tests/checkasm/svq1enc.c
> index 1a6f531141..f9abdcbff8 100644
> --- a/tests/checkasm/svq1enc.c
> +++ b/tests/checkasm/svq1enc.c
> @@ -18,7 +18,6 @@
> * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> */
>
> -#include "libavutil/mem.h"
> #include "libavutil/mem_internal.h"
>
> #include "libavcodec/svq1encdsp.h"
> @@ -26,11 +25,13 @@
> #include "checkasm.h"
>
> #define BUF_SIZE 1024
> +#define MIN_VAL (-255 - 5 * 127)
> +#define MAX_VAL ( 255 + 5 * 128)
>
> #define randomize(buf, len) \
> do { \
> for (int i = 0; i < len; i++) \
> - buf[i] = ((rnd() % 65281) - 32641); \
> + buf[i] = ((rnd() % (MAX_VAL - MIN_VAL + 1)) + MIN_VAL);
This is why formal methods are a good thing
Looks OK of course
/Tomas
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-13 8:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 15:41 [FFmpeg-devel] [PATCH] tests/checkasm/svq1enc: Use proper range for input Andreas Rheinhardt
2024-05-08 19:27 ` Andreas Rheinhardt
2024-05-13 8:40 ` Tomas Härdin
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