drm/amdgpu: fix division by zero with invalid uvd dimensions
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix division by zero with invalid uvd dimensions
From: Boyuan Zhang <[email protected]>
When width or height is less than 16, width_in_mb or height_in_mb becomes 0, leading to fs_in_mb being 0. This causes a division by zero when calculating num_dpb_buffer in H264 and H264 Perf decode paths.
Add validation to reject frames with width < 16 or height < 16 before performing any calculations that depend on these values.
V2: Format change - move up all vaiable definitions.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +7 -0
@@ -635,6 +635,13 @@ static int amdgpu_uvd_cs_msg_decode(struct amdgpu_device *adev, uint32_t *msg,unsigned int image_size, tmp, min_dpb_size, num_dpb_buffer;unsigned int min_ctx_size = ~0 ; +/* Reject invalid dimensions to prevent division by zero */ +if (width <16 || height <16 ) { +DRM_ERROR ("Invalid UVD decoding dimensions (%dx%d)!\n" , + width, height); +return -EINVAL ; + } + image_size = width * height; image_size += image_size /2 ; image_size =ALIGN (image_size,1024 );
Signature · 1 line
2.43.0
Quoted 24 lines · On Tue, May 19, 2026 at 1:21 PM <[email protected]> wrote:
From: Boyuan Zhang <[email protected]>
When width or height is less than 16,
width_in_mborheight_in_mbbecomes 0, leading tofs_in_mbbeing 0. This causes a division by zero when calculatingnum_dpb_bufferin H264 and H264 Perf decode paths.Add validation to reject frames with width < 16 or height < 16 before performing any calculations that depend on these values.
V2: Format change - move up all vaiable definitions.
Signed-off-by Boyuan Zhang <[email protected]>Reviewed-by Leo Liu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c static int amdgpu_uvd_cs_msg_decode(struct amdgpu_device *adev, uint32_t *msg, · line 641
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +4
-0@@ -635,6 +635,13 @@ static int amdgpu_uvd_cs_msg_decode(struct amdgpu_device *adev, uint32_t *msg,unsigned int image_size, tmp, min_dpb_size, num_dpb_buffer;unsigned int min_ctx_size = ~0 ; +/* Reject invalid dimensions to prevent division by zero */ +if (width <16 || height <16 ) { +DRM_ERROR ("Invalid UVD decoding dimensions (%dx%d)!\n" , + width, height);
I'd drop the message or make it warn_once. Otherwise you can spam the log. With that fixed:
Alex
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +3
-1+return -EINVAL ; + } + image_size = width * height; image_size += image_size /2 ; image_size =ALIGN (image_size,1024 ); --2.43.0