[Mapit] Fix for PNG-loading bug in PIL

Bernhard Herzog bh at intevation.de
Wed Aug 1 13:31:49 CEST 2001


I've fixed a long-standing bug in PIL's PNG loader. PIL sometimes had
problems loading PNG files and would fail with the message:
"IOError: decoder error -3 when reading image file".

The patch is included below. Apply it in PIL's libImaging subdirectory
and recompile. I posted the fix to the PIL mailing list, too, but I
haven't got a reply yet, so I don't know whether it will be in the next
PIL release.

   Bernhard


*** Zip.h.orig	Thu May  3 12:57:38 2001
--- Zip.h	Wed Jul 25 01:07:37 2001
***************
*** 38,43 ****
--- 38,45 ----
  
      UINT8* previous;		/* previous line (allocated) */
  
+     int last_output;		/* # bytes last output by inflate */
+ 
      /* Compressor specific stuff */
      UINT8* prior;		/* filter storage (allocated) */
      UINT8* up;
*** ZipDecode.c.orig	Thu May  3 12:57:38 2001
--- ZipDecode.c	Wed Jul 25 01:15:20 2001
***************
*** 51,56 ****
--- 51,58 ----
  	    return -1;
  	}
  
+ 	context->last_output = 0;
+ 
  	/* Initialize to black */
  	memset(context->previous, 0, state->bytes+1);
  
***************
*** 77,84 ****
      /* Decompress what we've got this far */
      while (context->z_stream.avail_in > 0) {
  
! 	context->z_stream.next_out = state->buffer;
! 	context->z_stream.avail_out = state->bytes + context->prefix;
  
  	err = inflate(&context->z_stream, Z_NO_FLUSH);
  
--- 79,87 ----
      /* Decompress what we've got this far */
      while (context->z_stream.avail_in > 0) {
  
! 	context->z_stream.next_out = state->buffer + context->last_output;
! 	context->z_stream.avail_out =
! 	    state->bytes + context->prefix - context->last_output;
  
  	err = inflate(&context->z_stream, Z_NO_FLUSH);
  
***************
*** 100,105 ****
--- 103,109 ----
  	if (n < state->bytes + context->prefix) {
  	    /* FIXME: if n is not zero, we're in trouble.  But can
  	       that really happen?  My tests say it cannot... */
+ 	    context->last_output = n;
  	    break; /* need more input data */
  	}
  
***************
*** 175,180 ****
--- 179,187 ----
  		       state->xsize);
  
  	state->y++;
+ 
+ 	/* all inflate output has been consumed */
+ 	context->last_output = 0;
  
  	if (state->y >= state->ysize || err == Z_STREAM_END) {
  



-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                               http://mapit.de/




More information about the Mapit mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)