fig2dev truncates PostScript image data when deflate stream size is exactly...
Xfig is a diagramming tool
Brought to you by:
tklxfiguser
I encountered a bug in the export of an imported raster image.
XFig displays the image correctly, but fig2dev produces a PostScript file in which the bottom part of the image is missing.
The problem is in fig2dev/dev/encode.c, in deflate_ascii85encode(). The output buffer is 16384 bytes, and the code ends with:
if (ret == Z_STREAM_END && strm.avail_out != 0)
ascii85encode(out, buf, sizeof buf - strm.avail_out);
For this offending image, the deflate stream is exactly 81920 bytes (5 × 16384). Thus deflate() returns Z_STREAM_END with strm.avail_out == 0, and the final 16384-byte buffer is not written. Only 65536 bytes are output.
Changing the condition to:
if (ret == Z_STREAM_END)
ascii85encode(out, buf, sizeof buf - strm.avail_out);
appears to fix the problem. This seems to be an edge case where the final deflate output buffer is exactly full.
Thank you, best regards
Awesome! The proposed patch fixes the problem, and does not seem to create other bugs. I am still writing a test for the issue.