From 7f09344989617536d033a02adfbea7303f208d0b Mon Sep 17 00:00:00 2001 From: Lain Date: Tue, 4 Mar 2025 16:47:11 -0800 Subject: [PATCH] frontend/widgets: Fix integer overflow If the crop values combined are larger than the width or height of the source, an integer overflow will occur. This fix converts the width/height values to int, and then clamps any negative values to 0. --- frontend/widgets/OBSBasicPreview.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/widgets/OBSBasicPreview.cpp b/frontend/widgets/OBSBasicPreview.cpp index a2d0dedff..b9c924f7a 100644 --- a/frontend/widgets/OBSBasicPreview.cpp +++ b/frontend/widgets/OBSBasicPreview.cpp @@ -414,8 +414,9 @@ static vec2 GetItemSize(obs_sceneitem_t *item) obs_sceneitem_get_scale(item, &scale); obs_sceneitem_get_crop(item, &crop); - size.x = float(obs_source_get_width(source) - crop.left - crop.right) * scale.x; - size.y = float(obs_source_get_height(source) - crop.top - crop.bottom) * scale.y; + size.x = fmaxf(float((int)obs_source_get_width(source) - crop.left - crop.right), 0.0f); + size.y = fmaxf(float((int)obs_source_get_height(source) - crop.top - crop.bottom), 0.0f); + vec2_mul(&size, &size, &scale); } return size;