Repository navigation
libnsgif: Fix the LZW code reader's off-by-one on the slow path (upstream 2255b2f74) (#2465) - #2468
Merged
Merged
Conversation
…ary)
A new cmocka test decodes GIFs with the vendored libnsgif directly (a
one-frame GIF goes to FFmpeg in gs_image_file, so test_image_file does
not reach libnsgif for it) and compares frame 0 with a reference PPM.
The first case is libnsgif's own regression test for upstream
2255b2f74: test/data/lzweod.gif and .ppm from netsurf-browser/libnsgif
9abf1190d (MIT, see libobs/graphics/libnsgif/LICENSE.libnsgif), added as
test/cmocka/data/libnsgif-lzweod.{gif,ppm}. The last LZW code ends on a
byte boundary at the end of the data.
RED: the decode reports success, but the last pixel is 0 0 0, expected
0 0 255.
Refs #2465
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ream 2255b2f74)
Backport of netsurf-browser/libnsgif 2255b2f74 ("lzw: Fix off-by-one on
code reader slow path", 2026-10-25), one line. When a code ends exactly
on a byte boundary, the slow path asked for one more byte than the code
needs. For the last code of the image data there is no next sub-block,
so it was lost: the decode reported success and the last pixels stayed
empty. Reads were always inside the sub-block, so this is a wrong image,
not a memory error.
GREEN: test_nsgif_decode decodes libnsgif-lzweod.gif as its reference.
Fixes #2465
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
|
Coordinator review: a one-line backport of libnsgif 2255b2f74 with upstream's regression image, and every read stays bounds-checked inside the sub-block. The new decode test is in test-graph.json, no existing test changes, and the ledger line is in. Queuing. |
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 #2465
What and why
The vendored libnsgif (1.0.0) lost the last LZW code of an image when that code ends exactly on a byte boundary at the end of the data: the code reader's slow path asked for one byte more than the code needs, and there is no next sub-block. The decode reported success, and the last pixels stayed empty. This backports upstream's one-line fix, netsurf-browser/libnsgif@2255b2f74 (2026-10-25), with upstream's regression image.
Not a memory error: every read stays inside the current sub-block (
ctx->sb_bit < ctx->sb_bit_countis checked before each read).libobs/graphics/libnsgif/lzw.c.h:175:(current_bit + code_size - 1) >> 3, as upstream.test_nsgif_decode(inbuild/test-graph.json): decodes GIFs with libnsgif directly and compares frame 0 with a reference PPM. A one-frame GIF goes to FFmpeg ings_image_file, sotest_image_filedoes not reach libnsgif for it. The LZW port (rust: Port the libnsgif LZW decoder (graphics/libnsgif/lzw.c.h) to obs-graphics (libnsgif slice 1) #2466) adds its characterization cases here.test/cmocka/data/libnsgif-lzweod.{gif,ppm}: libnsgif'stest/data/lzweod.{gif,ppm}from 9abf1190d (MIT,libobs/graphics/libnsgif/LICENSE.libnsgif).RED → GREEN
9c183035f:lzw_code_on_byte_boundary_at_end_of_datafails with "pixel 2 channel 2: 0, expected 255" (the last pixel black instead of blue; the decode itself reports success).f0bddbe31: passes.test_nsgif_decode,test_image_file,test_media_gif_last_frameand the other GIF tests pass (5/5, Linux x86_64).ci/local_gate.py --lane lint) passes, includingtest_cmocka_windows_diagnostics(the test prints withfprintf(stderr, …)and callsfail(), notfail_msg()).Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Sources and filters)