Description
What
A scan of a GIF in parts loses the GIF for good when a part ends inside a frame. nsgif_data_scan is made for data that arrives in parts (each call with all the data so far), but when the data ends inside a frame's image data or local colour table, or on the last byte of an extension, the next scan returns NSGIF_ERR_DATA_FRAME, and so does every scan after it, also with all the data. Frames after that point are never found.
Found while characterizing libnsgif for #2510; kept as found in the port (#2514) and in test_nsgif_decode (gif_scan_incremental, render::gif::gif_scan_incremental).
Cause
nsgif__process_frame (scan mode) saves the position where the frame's parse stopped as the resume point, also when that parse ended with NSGIF_ERR_END_OF_DATA:
cleanup:
if (!decode) {
gif->buf_pos = pos - gif->buf;
}By then the extensions, the image descriptor and the colour table of the frame are behind pos, so the next scan reads the frame's image data (or an extension's block terminator) as the next block. Upstream libnsgif has the same code (our gif.c is upstream HEAD).
Who it affects
- OBS: not today.
gs_image_filereads the whole file and scans it once (C and Rust). - Any caller that loads a GIF in parts: the API is made for that (NetSurf loads that way).
Fix
On NSGIF_ERR_END_OF_DATA in scan mode, resume at the frame's start (frame->frame_offset, kept already) and scan the frame again from there next time; the frame's fields are written again by that scan. Other errors keep their position, as now.
To check: the lzw_data_length that nsgif__parse_image_data adds up across a partial scan (only nsgif_data_complete reads it, as "greater than 0"), and the loop count of an application extension that a scan reads twice.
Plan
One PR, after #2514 (it changes obs_graphics::gif):
- RED:
gif_scan_incremental(cmocka and Tier 1) expects the end state of a whole scan for every split point and for a byte-by-byte scan, in place of the characterized bad frame. - GREEN: the fix in
libobs/graphics/libnsgif/gif.c.h(vendored C, still inlibobs-c-referenceand the C oracle) and inobs_graphics::gif, so Tier 3 (render::gif_parity, which scans in parts) keeps matching. - A report to upstream libnsgif (NetSurf) with the reproduction and the patch.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 26, 2026
Claiming: #2515
Plan as in the description: one PR on top of #2514 (RED: scans in parts give the end state of a whole scan; GREEN: the fix in the vendored C and in
obs_graphics::gif), then the upstream report.test: Scans of a GIF in parts end in the state of a whole scan (RED, #…
libnsgif: Resume a scan at the frame's start after the end of the data (
docs: ledger the #2515 GIF scan fix in Fixed upstream bugs (#2515)
rust/README.md: Describe the #2515 scan resume in the gif.c.h row
libnsgif: Resume a scan at the frame's start after the end of the data (