On Tue, 12 Aug 2008 20:08:38 +0200, Christoph wrote: > Thanks for the bug report. Unfortuntely I'm not familiar with libpng and > driftnet has been abandoned upstream. So I'd appreciate a patch dealing > with the libpng return codes.
Attached is a patch that uses libpng's error-handling to catch the error, clean up and continue. (I haven't fiddled with libpng before, so I hope it isn't too far of. It works work me (I get error messages printed and no crashing)). Best regards, Adam -- "What looks large from a distance Adam Sjøgren Close up is never that big" [EMAIL PROTECTED]
--- hip/driftnet-0.1.6/png.c 2008-08-11 23:20:02.000000000 +0200 +++ hop/driftnet-0.1.6/png.c 2008-08-13 19:56:24.941247135 +0200 @@ -29,6 +29,24 @@ } } +/* png_catch_error: */ +/* Catch errors signalled by libpng, clean up and go on. */ +void png_catch_error(png_structp png_ptr, png_const_charp error_msg) { + jmp_buf *jmpbuf_ptr; + + fprintf(stderr, "libpng error: %s (skipping image).\n", error_msg); + fflush(stderr); + + jmpbuf_ptr=png_jmpbuf(png_ptr); + if (jmpbuf_ptr==NULL) { + fprintf(stderr, "libpng unrecoverable error, terminating.\n"); + fflush(stderr); + exit(20); + } + + longjmp(jmpbuf_ptr, 1); +} + /* png_load_hdr: * Load the header of a PNG file. */ int png_load_hdr(img I) { @@ -38,12 +56,19 @@ return 0; } I->us = p; - p->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); + p->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_catch_error, NULL); if (p->png == 0) { png_done(I); I->err = IE_HDRFORMAT; return 0; } + + if (setjmp(png_jmpbuf(p->png))) { + png_done(I); + I->err = IE_HDRFORMAT; + return 0; + } + p->info = png_create_info_struct(p->png); if (p->info == 0) { png_done(I);