New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cups: GIF reader gif_read_lzw() may not return byte #3869

Closed
michaelrsweet opened this Issue Jun 20, 2011 · 1 comment

Comments

Projects
None yet
1 participant
@michaelrsweet
Copy link
Collaborator

michaelrsweet commented Jun 20, 2011

Version: 1.4.6
CUPS.org User: thoger

gif_read_lzw() is documented as:

523 /*
524 * 'gif_read_lzw()' - Read a byte from the LZW stream...
525 */

Its return value is int and it can actually return value >= 256. This can happen at least during the second call to gif_read_lzw(), when fresh == 1. Following code path is used in that case:

607 do
608 firstcode = oldcode = gif_get_code(fp, code_size, 0);
609 while (firstcode == clear_code);
610
611 return (firstcode);

An input GIF file can specify code_size up to 12 (see GIF_MAX_BITS check in gif_read_image()), which allows returned firstcode of up to 2^12-1. gif_read_image() uses returned value (stored in pixel) as an index to cmap[256][4], hence this leads to buffer over-read. In a quick test, I managed to get pixel value set to ~4k, but it did not trigger crash. I've not tried creating a better reproducer to see if it's actually possible to trigger a crash with this.

@michaelrsweet

This comment has been minimized.

Copy link
Collaborator Author

michaelrsweet commented Jun 20, 2011

CUPS.org User: mike

Duping this against STR #3867. Patch will be attached there...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment