[gs-cvs] rev 8778 - trunk/gs/jbig2dec
giles at ghostscript.com
giles at ghostscript.com
Mon May 26 12:04:05 PDT 2008
Author: giles
Date: 2008-05-26 12:04:05 -0700 (Mon, 26 May 2008)
New Revision: 8778
Modified:
trunk/gs/jbig2dec/jbig2_page.c
Log:
Work around broken JBIG2Decode streams created by several versions of
Xerox WorkCentre. Bugs 689841 and 689852.
In these streams, a segment data length field is written as -1
expecting the decoder to infer it from the length of the remaining
data.
Modified: trunk/gs/jbig2dec/jbig2_page.c
===================================================================
--- trunk/gs/jbig2dec/jbig2_page.c 2008-05-25 07:28:53 UTC (rev 8777)
+++ trunk/gs/jbig2dec/jbig2_page.c 2008-05-26 19:04:05 UTC (rev 8778)
@@ -194,12 +194,30 @@
*
* called upon seeing an 'end of page' segment, this routine
* marks a page as completed so it can be returned.
- * compositing will have already happened in the previous
+ * compositing will have already happened in the previous
* segment handlers.
**/
int
jbig2_complete_page (Jbig2Ctx *ctx)
{
+
+ /* check for unfinished segments */
+ if (ctx->segment_index != ctx->n_segments) {
+ Jbig2Segment *segment = ctx->segments[ctx->segment_index];
+ int code = 0;
+ /* Some versions of Xerox Workcentre generate PDF files
+ with the segment data length field of the last segment
+ set to -1. Try to cope with this here. */
+ if ((segment->data_length & 0xffffffff) == 0xffffffff) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
+ "File has an invalid segment data length!"
+ " Trying to decode using the available data.");
+ segment->data_length = ctx->buf_wr_ix - ctx->buf_rd_ix;
+ code = jbig2_parse_segment(ctx, segment, ctx->buf + ctx->buf_rd_ix);
+ ctx->buf_rd_ix += segment->data_length;
+ ctx->segment_index++;
+ }
+ }
ctx->pages[ctx->current_page].state = JBIG2_PAGE_COMPLETE;
return 0;
More information about the gs-cvs
mailing list