[gs-cvs] rev 7605 - trunk/gs/src

lpd at ghostscript.com lpd at ghostscript.com
Sat Jan 13 10:40:17 PST 2007


Author: lpd
Date: 2007-01-13 10:40:16 -0800 (Sat, 13 Jan 2007)
New Revision: 7605

Modified:
   trunk/gs/src/scfd.c
   trunk/gs/src/scfe.c
   trunk/gs/src/scfx.h
Log:
Fixes some long-standing data-dependent bugs in the CCITTFaxDecode filter
caused by incorrect initialization.  PS3 CET 23-12E-2.  Also cleans up some
formatting.


Modified: trunk/gs/src/scfd.c
===================================================================
--- trunk/gs/src/scfd.c	2007-01-12 22:15:32 UTC (rev 7604)
+++ trunk/gs/src/scfd.c	2007-01-13 18:40:16 UTC (rev 7605)
@@ -46,19 +46,18 @@
     /* Because skip_white_pixels can look as many as 4 bytes ahead, */
     /* we need to allow 4 extra bytes at the end of the row buffers. */
     ss->lbuf = gs_alloc_bytes(st->memory, raster + 4, "CFD lbuf");
+    memset(ss->lbuf, white, raster);
     ss->lprev = 0;
     if (ss->lbuf == 0)
-	return ERRC;
-/****** WRONG ******/
+	return ERRC;		/****** WRONG ******/
     if (ss->K != 0) {
 	ss->lprev = gs_alloc_bytes(st->memory, raster + 4, "CFD lprev");
 	if (ss->lprev == 0)
-	    return ERRC;
-/****** WRONG ******/
+	    return ERRC;	/****** WRONG ******/
 	/* Clear the initial reference line for 2-D encoding. */
-	memset(ss->lbuf, white, raster);
+	memset(ss->lprev, white, raster);
 	/* Ensure that the scan of the reference line will stop. */
-	ss->lbuf[raster] = 0xa0;
+	ss->lprev[raster] = 0xa0;
     }
     ss->k_left = min(ss->K, 0);
     ss->run_color = 0;
@@ -66,9 +65,9 @@
     ss->skipping_damage = false;
     ss->cbit = 0;
     ss->uncomp_run = 0;
-    ss->rows_left = (ss->Rows <= 0 || ss->EndOfBlock ? -1 : ss->Rows + 1);
+    ss->rows_left = (ss->Rows <= 0 || ss->EndOfBlock ? -1 : ss->Rows);
     ss->row = 0;
-    ss->rpos = ss->wpos = raster - 1;
+    ss->rpos = ss->wpos = -1;
     ss->eol_count = 0;
     ss->invert = white;
     ss->min_left = 1;
@@ -357,7 +356,7 @@
 	if_debug0('w', "[w1]new row\n");
 	status = cf_decode_1d(ss, pr);
     } else {
-	if_debug1('w', "[w1]new 2-D row, %d left\n", k_left);
+	if_debug1('w', "[w1]new 2-D row, k_left=%d\n", k_left);
 	status = cf_decode_2d(ss, pr);
     }
     if_debug3('w', "[w]CFD status = %d, wpos = %d, cbit = %d\n",
@@ -372,7 +371,7 @@
 		)
 		break;
 	    /* Substitute undamaged data if appropriate. */
-/****** NOT IMPLEMENTED YET ******/
+	    /****** NOT IMPLEMENTED YET ******/
 	    {
 		ss->wpos = wstop;
 		ss->cbit = -ss->Columns & 7;
@@ -490,7 +489,7 @@
     get_run(cf_black_decode, cfd_black_initial_bits, cfd_black_min_bits,
 	    bcnt, "[w1]black", dbl, out1);
     if (bcnt < 0) {		/* All exceptional codes are invalid here. */
-/****** WRONG, uncompressed IS ALLOWED ******/
+	/****** WRONG, uncompressed IS ALLOWED ******/
 	status = ERRC;
 	goto out;
     }
@@ -812,8 +811,7 @@
 	    qbit += 8, q++;
 	rlen &= 1;
     }
-  out:
-/******* WRONG ******/
+  out:				/******* WRONG ******/
     cfd_store_state();
     return rlen;
 }

Modified: trunk/gs/src/scfe.c
===================================================================
--- trunk/gs/src/scfe.c	2007-01-12 22:15:32 UTC (rev 7604)
+++ trunk/gs/src/scfe.c	2007-01-13 18:40:16 UTC (rev 7605)
@@ -266,10 +266,10 @@
 	}
 #ifdef DEBUG
 	if (ss->K > 0) {
-	    if_debug1('w', "[w]new row, k_left=%d\n",
-		      ss->k_left);
+	    if_debug2('w', "[w2]new %d-D row, k_left=%d\n",
+		      (ss->k_left == 1 ? 1 : 2), ss->k_left);
 	} else {
-	    if_debug0('w', "[w]new row\n");
+	    if_debug1('w', "[w%d]new row\n", (ss->K < 0 ? 2 : 1));
 	}
 #endif
 	/*

Modified: trunk/gs/src/scfx.h
===================================================================
--- trunk/gs/src/scfx.h	2007-01-12 22:15:32 UTC (rev 7604)
+++ trunk/gs/src/scfx.h	2007-01-13 18:40:16 UTC (rev 7605)
@@ -87,31 +87,30 @@
 /* CCITTFaxDecode */
 typedef struct stream_CFD_state_s {
     stream_CF_state_common;
-    int cbit;			/* bits left to fill in current decoded */
-    /* byte at lbuf[wpos] (0..7) */
+    int cbit;			/* bits left to fill in current decoded
+				   byte at lbuf[wpos] (0..7) */
     int rows_left;		/* number of rows left */
     int row;			/* current row, first is 0 */
     int rpos;			/* rptr for copying lbuf to client */
-    int wpos;			/* rlimit/wptr for filling lbuf or */
-    /* copying to client */
+    int wpos;			/* rlimit/wptr for filling lbuf or
+				   copying to client */
     int eol_count;		/* number of EOLs seen so far */
-    byte invert;		/* current value of 'white' */
-    /* for 2-D decoding */
-    int run_color;		/* -1 if processing white run, */
-    /* 0 if between runs but white is next, */
-    /* 1 if between runs and black is next, */
-    /* 2 if processing black run */
-    int damaged_rows;		/* # of consecutive damaged rows preceding */
-    /* the current row */
-    bool skipping_damage;	/* true if skipping a damaged row looking */
-    /* for EOL */
+    byte invert;		/* current value of 'white' for 2-D decoding */
+    int run_color;		/* -1 if processing white run,
+				   0 if between runs but white is next,
+				   1 if between runs and black is next,
+				   2 if processing black run */
+    int damaged_rows;		/* # of consecutive damaged rows preceding
+				   the current row */
+    bool skipping_damage;	/* true if skipping a damaged row looking
+				   for EOL */
     /* The following are not used yet. */
-    int uncomp_run;		/* non-0 iff we are in an uncompressed */
-    /* run straddling a scan line (-1 if white, */
-    /* 1 if black) */
+    int uncomp_run;		/* non-0 iff we are in an uncompressed
+				   run straddling a scan line (-1 if white,
+				   1 if black) */
     int uncomp_left;		/* # of bits left in the run */
-    int uncomp_exit;		/* non-0 iff this is an exit run */
-    /* (-1 if next run white, 1 if black) */
+    int uncomp_exit;		/* non-0 iff this is an exit run
+				   (-1 if next run white, 1 if black) */
 } stream_CFD_state;
 
 #define private_st_CFD_state()	/* in scfd.c */\



More information about the gs-cvs mailing list