PR #26235 opened by Jun Zhao (mypopydev) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26235 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26235.patch
Two small fixes for oversized buffers in the VVC checkasm tests. Both are test-only; no library code changes. vvc_alf.c: the four ALF classify index arrays (class_idx / transpose_idx) were dimensioned with SRC_BUF_SIZE, a byte count for the uint8_t pixel buffers. Reused as an int element count, that made each array 150 KiB instead of 4 KiB. They now use ALF_MAX_BLOCKS_IN_CTU (1024 ints), the exact bound the decoder itself uses. vvc_mc.c: the DMVR destinations were declared uint16_t[DST_BUF_SIZE], twice the intended size, and the memset cleared only half of it. Using DST_BUF_SIZE / 2 gives 32768 bytes, so the existing memset now covers the whole buffer. checkasm passes for vvc_alf (4032), vvc_mc (1247) and vvc_sao (36). A guard-region canary on this build confirms no SIMD write crosses the 1024-int boundary, so the exact-sized buffers are safe. The -Wstack-usage warning is not cleared by these changes; that needs a separate heap move. >From 150d535452735aaaa3d36bee2345c25f7de8e646 Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Fri, 20 Nov 2026 20:23:26 +0800 Subject: [PATCH 1/2] tests/checkasm/vvc_alf: size ALF classify index buffers by block count class_idx and transpose_idx hold one int per 4x4 ALF block. For the largest case (128x128) that is 1024 ints, and the decoder allocates exactly ALF_MAX_BLOCKS_IN_CTU ints for the same array (libavcodec/vvc/filter.c). The checkasm buffers were instead dimensioned with SRC_BUF_SIZE, which is a byte count for the uint8_t pixel buffers (38592). Used as an int element count, that made each of the four arrays 154368 bytes instead of 4096. Only id_size bytes were ever compared, so the 37.7x over-allocation went unnoticed and pushed check_alf_classify's stack frame to 746 KiB. Use ALF_MAX_BLOCKS_IN_CTU. The C reference writes exactly 1024 ints; the x86 tail stores are exact-width and the aarch64 stores scalar, so no headroom is needed. A guard-region canary on this build (all sizes, bit depths and NEON/SME2 variants) confirms nothing is written past 1024 ints. The frame drops to 159 KiB, still above the 120 KiB -Wstack-usage threshold; removing the warning requires moving the buffers to the heap, which is a separate change. Signed-off-by: Jun Zhao <[email protected]> --- tests/checkasm/vvc_alf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/checkasm/vvc_alf.c b/tests/checkasm/vvc_alf.c index fcb9ca0bc0d..b6ca2d354fa 100644 --- a/tests/checkasm/vvc_alf.c +++ b/tests/checkasm/vvc_alf.c @@ -133,10 +133,10 @@ static void check_alf_filter(VVCDSPContext *c, const int bit_depth) static void check_alf_classify(VVCDSPContext *c, const int bit_depth) { - LOCAL_ALIGNED_32(int, class_idx0, [SRC_BUF_SIZE]); - LOCAL_ALIGNED_32(int, transpose_idx0, [SRC_BUF_SIZE]); - LOCAL_ALIGNED_32(int, class_idx1, [SRC_BUF_SIZE]); - LOCAL_ALIGNED_32(int, transpose_idx1, [SRC_BUF_SIZE]); + LOCAL_ALIGNED_32(int, class_idx0, [ALF_MAX_BLOCKS_IN_CTU]); + LOCAL_ALIGNED_32(int, transpose_idx0, [ALF_MAX_BLOCKS_IN_CTU]); + LOCAL_ALIGNED_32(int, class_idx1, [ALF_MAX_BLOCKS_IN_CTU]); + LOCAL_ALIGNED_32(int, transpose_idx1, [ALF_MAX_BLOCKS_IN_CTU]); LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]); LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]); LOCAL_ALIGNED_32(int32_t, alf_gradient_tmp, [ALF_GRADIENT_SIZE * ALF_GRADIENT_SIZE * ALF_NUM_DIR]); -- 2.54.1 >From 8fbd310bd87c6e0281977113d11502bc648fb75d Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Fri, 20 Nov 2026 20:23:27 +0800 Subject: [PATCH 2/2] tests/checkasm/vvc_mc: fix DMVR destination buffer element count DST_BUF_SIZE is a byte count (32768), but the DMVR destination buffers were declared as uint16_t[DST_BUF_SIZE], making each 65536 bytes. The memset clears only DST_BUF_SIZE bytes, so the upper half was never zeroed. Use the DST_BUF_SIZE / 2 conversion already applied to the int16_t destination buffers elsewhere in this file, giving 32768 bytes that the existing memset fully covers. The output comparison reads at most ~5 KiB, well inside. Signed-off-by: Jun Zhao <[email protected]> --- tests/checkasm/vvc_mc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/checkasm/vvc_mc.c b/tests/checkasm/vvc_mc.c index a59a11d9ce7..a5513861db1 100644 --- a/tests/checkasm/vvc_mc.c +++ b/tests/checkasm/vvc_mc.c @@ -335,8 +335,8 @@ static av_noinline void check_avg(void) #define SR_RANGE 2 static av_noinline void check_dmvr(void) { - LOCAL_ALIGNED_32(uint16_t, dst0, [DST_BUF_SIZE]); - LOCAL_ALIGNED_32(uint16_t, dst1, [DST_BUF_SIZE]); + LOCAL_ALIGNED_32(uint16_t, dst0, [DST_BUF_SIZE / 2]); + LOCAL_ALIGNED_32(uint16_t, dst1, [DST_BUF_SIZE / 2]); LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]); LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]); const int dst_stride = MAX_PB_SIZE; -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
