Repository navigation
Description
Upstream bug: obsproject/obs-studio master (7fc60ea38) has the same code in libobs/obs-scene.c; no upstream issue found. OBS never writes these values itself, so this only shows with scene collections edited by hand or written by other tools. The result is a wrong size, not memory corruption.
Location
libobs/obs-scene.c.h on master 209d977:
scene_load_item(), lines 1046-1049: the crop from the file goes straight into the item'sintfields.item->crop.left = (uint32_t)obs_data_get_int(item_data, "crop_left");
obs_sceneitem_set_crop()(2997-3004) clamps a negative crop to 0; the load does not.calc_cx()andcalc_cy(), lines 355 and 361: fourintcrops are added up in anint, which can overflow.uint32_t crop_cx = item->crop.left + item->crop.right + item->bounds_crop.left + item->bounds_crop.right; return (crop_cx > width) ? 2 : (width - crop_cx);
update_nested_scene_crop(), lines 388-391:(int)((float)item->crop.left * scale_x), undefined when the product is outside theintrange.render_item(), lines 762-763:(float)(item->crop.left + item->bounds_crop.left), also anintsum.resize_scene_base(), lines 3285-3286: a group's size is(uint32_t)ceilf(scale->x), undefined when the extent is outside theuint32_trange.
Class
Logic error / integer overflow (undefined behaviour in C). The result is a wrong size, not memory corruption.
How it is reached
Loading a scene collection whose scene item has, for example, "crop_left": -100. Before the crop sum is compared, it is converted to unsigned, so it comes out larger than any source and the item is drawn 2 px wide (or high). A crop of 2^31 or more comes back with the other sign (3000000000 is loaded as -1294967296). Then:
- a nested scene with a large crop that grows a lot (a crop of 1000000000 on a 1x1 scene that becomes 4000x4000) gets an
INT_MINcrop on x86-64, so it is drawn 2 px wide; - a group whose sources are 1e20 px apart gets a size of 0 on x86-64.
Memory safety: checked; these give only wrong sizes. Each item's drawn size is at most the source size, or 2. The crop only goes into the render matrix as a float translation. A huge group size makes texture creation fail. A scene collection can already set a custom scene size of up to UINT32_MAX anyway. The frontend and obs-websocket use obs_sceneitem_get_crop() only for arithmetic and display, never as an index or allocation size.
Proposed fix and failing test
- Load: read each crop as the nearest
int, then set it throughobs_sceneitem_set_crop(), so the setter's clamp is the only rule. - Casts and sums: add the crops in 64 bits, and give each float cast the nearest value in range (0 for NaN or a negative size). Every value in range gives the result it gave before.
- The arithmetic moves to static inline helpers in
obs-scene.h, so a test can build it with UBSan.
Tests:
test_scene_item_crop_loadloads sources and scenes from a JSON string withobs_load_sources()through the real libobs. It covers a negative crop, a crop past the int range, a crop sum past the int range, a nested scene that grows, a group 1e20 px wide and an in-range control. On master 4 of 6 fail: the negative crop is kept and the item is drawn 2 x 2; 3000000000 comes back as -1294967296; the grown nested crop isINT_MIN; the group is 0 x 0.test_scene_crop_stepscovers the helpers with-fsanitize=undefined,float-cast-overflow -fno-sanitize-recover. With master's arithmetic it fails withruntime error: signed integer overflow: 2147483647 + 2147483647 cannot be represented in type 'int'.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 22, 2026
Claiming: #1839. Tests and fix are ready; PR follows.
libobs: Saturate the scene item crop and group size casts
libobs: Clamp loaded scene item crops and saturate the crop and group…