Skip to content

Commit

Permalink
ngiflibSDL.c: do not coredump on GIF without any palette
Browse files Browse the repository at this point in the history
fixes #22
  • Loading branch information
miniupnp committed Mar 4, 2023
1 parent 3a44ac7 commit 231df82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Binary file added invalid_gif/issue_22_CA_file2_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 16 additions & 12 deletions ngiflibSDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,23 @@ struct ngiflibSDL_animation * SDL_LoadAnimatedGif(const char * file)
current_palette = gif->palette;
current_palette_size = gif->ncolors;
}
for(i = 0; i < current_palette_size; i++) {
surface->format->palette->colors[i].r = current_palette[i].r;
surface->format->palette->colors[i].g = current_palette[i].g;
surface->format->palette->colors[i].b = current_palette[i].b;
//printf("#%02x%02x%02x ", current_palette[i].r, current_palette[i].g, current_palette[i].b);
}
for(; i < gif->ncolors; i++) {
surface->format->palette->colors[i].r = gif->palette[i].r;
surface->format->palette->colors[i].g = gif->palette[i].g;
surface->format->palette->colors[i].b = gif->palette[i].b;
//printf("#%02x%02x%02x ", gif->palette[i].r, gif->palette[i].g, gif->palette[i].b);
if (current_palette != NULL) {
for(i = 0; i < current_palette_size; i++) {
surface->format->palette->colors[i].r = current_palette[i].r;
surface->format->palette->colors[i].g = current_palette[i].g;
surface->format->palette->colors[i].b = current_palette[i].b;
//printf("#%02x%02x%02x ", current_palette[i].r, current_palette[i].g, current_palette[i].b);
}
for(; i < gif->ncolors; i++) {
surface->format->palette->colors[i].r = gif->palette[i].r;
surface->format->palette->colors[i].g = gif->palette[i].g;
surface->format->palette->colors[i].b = gif->palette[i].b;
//printf("#%02x%02x%02x ", gif->palette[i].r, gif->palette[i].g, gif->palette[i].b);
}
//printf("\n");
} else {
fprintf(stderr, "no palette in GIF\n");
}
printf("\n");
psrc = p; pdst = surface->pixels;
for(i=0; i<gif->height; i++) {
ngiflib_memcpy(pdst, psrc, gif->width);
Expand Down

0 comments on commit 231df82

Please # to comment.