Repository navigation
libobs: Reject an image too large for a texture before decoding it - #1474
Merged
Merged
Conversation
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 20, 2026
An Image source given a picture larger than the graphics device's texture size limit decodes all of it, holds up to three full-size copies, stalls the loading thread for seconds, and only then fails to create the texture. The test finds the device limit, loads PNGs one pixel wider and one pixel taller than it, and expects them to fail with a log line naming the size and the limit, without the peak resident memory growing. Pictures at the limit and small ones must still load. Refs obs-rust#1473
An image larger than the graphics device's texture size limit was decoded in full, with up to three full-size copies (2.5 GB for a 20480x11520 PNG), and stalled the loading thread for seconds before the texture creation failed. gs_create() now records the device's limit: GL_MAX_TEXTURE_SIZE from the OpenGL module through a new optional device export, and the API limit of 16384 for Direct3D 11 and Metal. The image decoder checks the picture's size once the header has been read (in its get_buffer2 callback) and gives up before decoding pixels, logging the size and the limit. With no graphics device the check is off. For a single-stream picture the demuxer already names the codec, so avformat_find_stream_info() is skipped: it decoded the whole picture once more, without any size check, only to learn its size and pixel format, which now come from the decoded frame. Fixes obs-rust#1473
zackees
force-pushed
the
fix/image-size-precheck
branch
from
October 20, 2026 02:12
52511a3 to
afac6ed
Compare
zackees
enabled auto-merge
October 20, 2026 02:12
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1473
What and why
An Image source given a picture larger than the GPU's texture size limit now fails at once, with a log line that gives the size and the limit. Before, OBS decoded the whole picture, held up to three full-size copies (2.5 GB for a 20480x11520 PNG) and blocked the loading thread for seconds, and only then did the texture creation fail (upstream obsproject/obs-studio#3427, reported by micolous, closed as stale).
device_texture_create().ffmpeg_image_init()calledavformat_find_stream_info(), which decodes the whole picture to learn its size and pixel format.ffmpeg_image_decode()then decoded it again, andffmpeg_image_reformat_frame()made more full-size copies.gs_create()now records the device's texture size limit, and any thread can read it. The OpenGL module reportsGL_MAX_TEXTURE_SIZEthrough a new optional export,device_get_max_texture_size. For Direct3D 11 and Metal, which don't have the export, libobs uses 16384, their API upper bound. Upstream maintainers pointed out that the limit differs between devices, so it is read from the device, not hard-coded.get_buffer2callback, which the decoder calls after it has read the header and before it decodes any pixels. It also checks container dimensions (for example AVIF) before the decoder opens. An oversized picture is logged once:Image '<file>' is 20480x11520, larger than the maximum texture size of the graphics device (16384x16384); not loading it. On Windows, the WIC fallback isn't tried for such a picture.avformat_find_stream_info()is skipped. The size and pixel format now come from the decoded frame. Multi-stream files and unknown codecs still get the probe.Headless (private Xvfb, private D-Bus, fresh HOME), OpenGL (llvmpipe, limit 16384). Image source added with obs-websocket CreateInput, peak RSS read from VmHWM:
device_texture_create (GL) failedRED → GREEN
test: Fail an oversized image before decoding it.test_image_size_precheck(cmocka, Linux, core video with libobs-opengl under xvfb-run; it skips without a display) finds the device limit by creating 1-pixel-high textures. It writes PNGs row by row with zlib, so making them costs no memory. A 16385x8192 picture and a 16x16385 one must fail to load, with peak RSS growth of at most 32 MiB and a log line naming the size and "texture size". Pictures at the limit (16384x16, 16x16384) and a small one must load and get a texture. On master, 2 of 4 fail:too_wide_fails_before_decoding(peak RSS +1420 MiB, 0.74 s) andtoo_tall_fails_before_decoding(no log line).ctest -j4(C lane, under xvfb-run): 318/318 passed, none skipped, includingtest_image_exif_orientation(JPEG/PNG/WebP decode without the probe). Format check against master with a small harness overgs_create_texture_file_data3(): 17/17 files are byte-identical. The changed code (graphics-ffmpeg, graphics.c, libobs-opengl) has no Rust port, so only the C lane was built.Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Sources and filters)-W..., ratchets): not applicable