Skip to content

Fix integer overflow in texture size calculations for large images#13184

Open
xtfo wants to merge 3 commits intoobsproject:masterfrom
xtfo:fix-texture-size-overflow
Open

Fix integer overflow in texture size calculations for large images#13184
xtfo wants to merge 3 commits intoobsproject:masterfrom
xtfo:fix-texture-size-overflow

Conversation

@xtfo
Copy link
Contributor

@xtfo xtfo commented Mar 3, 2026

Description

Fix integer overflow in texture size calculations across the D3D11 and OpenGL backends, and in image file memory tracking.

Motivation and Context

Loading large images within D3D11's resource limits crashes OBS due to a uint32_t overflow in the buffer size math. I also looked around a bit and found the same issue in the OpenGL and image-file code, so I've included those fixes here too.

Closes #11921
Supersedes #13183

How Has This Been Tested?

Loaded a large image that previously caused a crash. Image now loads and displays correctly. Verified in a debugger that the calculations in the OpenGL and image-file code paths produce correct values.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

xtfo added 3 commits March 3, 2026 02:19
The intermediate multiplication in BackupTexture and InitSRD can
exceed UINT32_MAX for large textures, causing the value to wrap
around. This results in truncated subresource data being passed
to CreateTexture2D, which causes the driver to read out of bounds
and crash.

Cast to uint64_t before the multiply to prevent overflow.
The intermediate multiplication in upload_texture_2d can exceed
UINT32_MAX for large textures, causing the value to wrap around.
While the result is only used for compressed textures, fix the
calculation for correctness.
The memory usage calculation in gs_image_file_init_internal can
overflow uint32_t for large images. Cast to uint64_t to prevent
the multiplication from wrapping around.
@prgmitchell
Copy link
Member

Can confirm these changes allow me to properly load a 16000x9000 image in an image source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash, because of "nvwgf2umx.dll" ?

2 participants