Skip to content

bug: libnsgif: a scan in parts that ends inside a frame never recovers (NSGIF_ERR_DATA_FRAME) #2515

Closed

Description

@vpacher

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_file reads 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):

  1. 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.
  2. GREEN: the fix in libobs/graphics/libnsgif/gif.c.h (vendored C, still in libobs-c-reference and the C oracle) and in obs_graphics::gif, so Tier 3 (render::gif_parity, which scans in parts) keeps matching.
  3. A report to upstream libnsgif (NetSurf) with the reproduction and the patch.

Activity

  1. vpacher commented on Oct 26, 2026

    @vpacher
    MemberAuthor

    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.

  2. self-assigned this
    on Oct 26, 2026
  3. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions