diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-03 19:11:14 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-03 19:28:33 +0000 |
commit | 8019292b7adabf81794dddf6bcf126d440ab229f (patch) | |
tree | e28f3cc5d6230bc40ca83bb4a56669b23766373e /test | |
parent | 0d5b742134940c65baa937697b39b94cc22a4e74 (diff) | |
download | libnsgif-8019292b7adabf81794dddf6bcf126d440ab229f.tar.gz libnsgif-8019292b7adabf81794dddf6bcf126d440ab229f.tar.bz2 |
Test: Make decoder more tolerant of bad gifs.
This makes us keep going if the scan or a frame decode fails,
ensuring everything is tested.
Diffstat (limited to 'test')
-rw-r--r-- | test/nsgif.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/test/nsgif.c b/test/nsgif.c index bac9061..76d7b8f 100644 --- a/test/nsgif.c +++ b/test/nsgif.c @@ -207,21 +207,21 @@ static void decode(FILE* ppm, const char *name, nsgif_t *gif) } frame_prev = frame_new; - err = nsgif_frame_decode(gif, frame_new, &bitmap); - if (err != NSGIF_OK) { - warning("nsgif_decode_frame", err); - return; - } - if (nsgif_options.info == true) { const nsgif_frame_info_t *f_info; f_info = nsgif_get_frame_info(gif, frame_new); - assert(f_info != NULL); - print_gif_frame_info(f_info); + if (f_info != NULL) { + print_gif_frame_info(f_info); + } } - if (ppm != NULL) { + err = nsgif_frame_decode(gif, frame_new, &bitmap); + if (err != NSGIF_OK) { + warning("nsgif_decode_frame", err); + /* Continue decoding the rest of the frames. */ + + } else if (ppm != NULL) { fprintf(ppm, "# frame %u:\n", frame_new); image = (const uint8_t *) bitmap; for (uint32_t y = 0; y != info->height; y++) { @@ -284,10 +284,9 @@ int main(int argc, char *argv[]) /* Scan the raw data */ err = nsgif_data_scan(gif, size, data); if (err != NSGIF_OK) { + /* Not fatal; some GIFs are nasty. Can still try to decode + * any frames that were decoded successfully. */ warning("nsgif_data_scan", err); - nsgif_destroy(gif); - free(data); - return EXIT_FAILURE; } if (nsgif_options.loops == 0) { |