Menu

#205 EGifPutImageDesc: unreachable guard, and writes whose result is discarded

v1.0_(example)
open
nobody
None
1
2026-08-21
2026-08-21
Nexory
No

Two defects in EGifPutImageDesc, both about error handling the function does
correctly elsewhere. One patch per finding attached.

  1. The guard against a second image descriptor can never fire. It requires
    PixelCount > 0xffff0000UL, but PixelCount is Width * Height and both come from
    16-bit fields, so it is at most 65535 * 65535 = 4294836225, which is 65535
    below the threshold. E_GIF_ERR_HAS_IMAG_DSCR is unreachable code.

Writing a second descriptor while an image is open therefore succeeds
silently, and giflib's own reader then rejects the file: DGifSlurp returns
D_GIF_ERR_READ_FAILED with ImageCount 0. The patch checks for outstanding
pixels instead; a finished image has PixelCount 0, so animations are
unaffected.

  1. The function discards the result of the image separator write, of the four
    EGifPutWord calls, of the packed field write and of EGifSetupCompress. Its own
    colour map loop ten lines further down checks every write and returns
    GIF_ERROR, and so does EGifPutScreenDesc. With a writer that fails from a
    chosen point on, EGifPutImageDesc ran through seven failed writes and still
    returned GIF_OK with Error 0. It now stops at the first one and reports
    E_GIF_ERR_WRITE_FAILED, which is what the sister function does.

make check is unchanged at 51 tests, 0 failures. Both proof-of-concept
programs are attached; each carries a control case, so a broken harness
cannot pass as a result.

The suite drives the command line tools and compiles nothing, so there is no
place for a C-level regression test in the current style. Happy to add one if
you want the suite extended that way.

Patch #37 retypes PixelCount in this same function. That does not reach
finding 1: the bound comes from the 16-bit width and height fields, not from
the type. The two changes touch different lines.

4 Attachments

Discussion


Log in to post a comment.