Hylafax Developers Mailing List Archives

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-devel] Faxq looping, libtiff changes, and a big mess



Well I finally have gotten around to trying the 'latest' hylafax, or at least
the one in the freebsd ports collection (4.0pl2).  I figured I had better do it
soon since there's talk of removing it from the ports collection due to its
long standing security problems and the important fact that it doesn't work,
either.

Sure enough, it is indeed broken.  It turns out someone decided to
change some of _TIFFFax3fillruns()'s parameters from uint16 to uint32's. 
Because of the obscure way hylafax uses the library (e.g. by importing header
files that aren't part of the 'official' api, and by calling TIFFFax3fillruns()
(which is declared extern, so I guess it really is exported?) this caused an
incompatibility problem that wouldn't normally occur.  And simply
fixing the code won't really solve the problem, since the library version of
libtiff didn't increase when the incompatible change was made.  But anyway, a
fix is enclosed to allow newly built hylafaxes to work with the new libtiff.

The patch is against 4.0pl2, so you may need to adapt it to whatever is current.

Issues raised:
        tif_fax3.h really shouldn't be in the hylafax distribution.  A better,
        more easily standardized interface to libtiff should be used, even if it
        requires changes to libtiff. 

        The arrays of runs could have been converted to uint32's just before
        calling _TIFFax3fillruns(), or everywhere in the code.  On the theory
        that there was a reason why they were changed in libtiff, I changed
        them everywhere in the code (at least I hope I did).  Although, to be
        honest, I have a hard time seeing how runs that big will ever appear in
        faxes.

So anyway, this fixes the looping faxq problem and the other associated 
problems you would have observed with decoding fax data if you had been able to
receive it.  Now whoever else is working on this will hopefully be motivated to
fix the security problem(s), maybe even link hfaxd against libwrap, and
actually get a new release out!  It really is a nice package, and I'm very
pleased with what it can do.

Best,
Cyrus

diff -ru ../hylafax-v4.0pl2.dist/faxd/CopyQuality.c++ ./faxd/CopyQuality.c++
--- ../hylafax-v4.0pl2.dist/faxd/CopyQuality.c++	Sat Feb 14 05:49:17 1998
+++ ./faxd/CopyQuality.c++	Sun Apr 23 19:41:43 2000
@@ -51,7 +51,7 @@
     setupDecoder(conf.recvFillOrder, params.is2D());
 
     u_int rowpixels = params.pageWidth();	// NB: assume rowpixels <= 2432
-    uint16 runs[2*2432];			// run arrays for cur+ref rows
+    uint32 runs[2*2432];			// run arrays for cur+ref rows
     setRuns(runs, runs+2432, rowpixels);
 
     recvEOLCount = 0;				// count of EOL codes
diff -ru ../hylafax-v4.0pl2.dist/faxd/G3Decoder.c++ ./faxd/G3Decoder.c++
--- ../hylafax-v4.0pl2.dist/faxd/G3Decoder.c++	Sat Feb 14 05:49:28 1998
+++ ./faxd/G3Decoder.c++	Sun Apr 23 19:44:29 2000
@@ -41,13 +41,13 @@
     DECLARE_STATE_EOL();						\
     int a0;				/* reference element */		\
     int RunLength;			/* length of current run */	\
-    uint16* pa;				/* place to stuff next run */	\
-    uint16* thisrun;			/* current row's run array */	\
+    uint32* pa;				/* place to stuff next run */	\
+    uint32* thisrun;			/* current row's run array */	\
     const TIFFFaxTabEnt* TabEnt
 #define	DECLARE_STATE_2D()						\
     DECLARE_STATE();							\
     int b1;				/* next change on prev line */	\
-    uint16* pb				/* next run in reference line */
+    uint32* pb				/* next run in reference line */
 /*
  * Load any state that may be changed during decoding.
  */
@@ -113,7 +113,7 @@
 }
 
 void
-G3Decoder::setRuns(uint16* cr, uint16* rr, int w)
+G3Decoder::setRuns(uint32* cr, uint32* rr, int w)
 {
     curruns = cr;
     if (refruns = rr) {
@@ -134,7 +134,7 @@
 {
     u_int rowbytes = howmany(w, 8);
     if (curruns == NULL) {
-	uint16 runs[2*2432];		// run arrays for cur+ref rows
+	uint32 runs[2*2432];		// run arrays for cur+ref rows
 	setRuns(runs, runs+2432, w);
 	while (h-- > 0) {
 	    decodeRow(raster, w);
@@ -232,10 +232,10 @@
     if (!nullrow)
 	RTCrun = 0;
     if (scanline)
-	_TIFFFax3fillruns((u_char*) scanline, thisrun, pa, lastx);
+	_TIFFFax3fillruns((u_char*) scanline, (uint32*)thisrun, (uint32*)pa, lastx);
     if (is2D) {
 	SETVAL(0);			// imaginary change for reference
-	SWAP(uint16*, curruns, refruns);
+	SWAP(uint32*, curruns, refruns);
     }
     rowref++;
     UNCACHE_STATE();
diff -ru ../hylafax-v4.0pl2.dist/faxd/G3Decoder.h ./faxd/G3Decoder.h
--- ../hylafax-v4.0pl2.dist/faxd/G3Decoder.h	Sat Feb 14 05:48:53 1998
+++ ./faxd/G3Decoder.h	Sun Apr 23 19:14:47 2000
@@ -43,8 +43,8 @@
     int		RTCrun;		// count of consecutive zero-length rows
     int		rowref;		// reference count of rows decoded
     int		RTCrow;		// row number of start of RTC
-    uint16*	refruns;	// runs for reference line
-    uint16*	curruns;	// runs for current line
+    uint32*	refruns;	// runs for reference line
+    uint32*	curruns;	// runs for current line
     const u_char* bitmap;	// bit reversal table
 protected:
     G3Decoder();
@@ -68,8 +68,8 @@
     virtual ~G3Decoder();
 
     void	setupDecoder(u_int fillorder, fxBool is2D);
-    void	setRuns(uint16*, uint16*, int);
-    uint16*	lastRuns();
+    void	setRuns(uint32*, uint32*, int);
+    uint32*	lastRuns();
 
     void	decode(void* raster, u_int w, u_int h);
     fxBool	decodeRow(void* scanline, u_int w);
@@ -92,7 +92,7 @@
 #define	EOFraised()		(sigsetjmp(jmpEOF, 0) != 0)
 #define	RTCraised()		(sigsetjmp(jmpRTC, 0) != 0)
 
-inline uint16* G3Decoder::lastRuns()	{ return is2D ? refruns : curruns; }
+inline uint32* G3Decoder::lastRuns()	{ return is2D ? refruns : curruns; }
 inline const u_char* G3Decoder::getBitmap()	{ return bitmap; }
 inline int G3Decoder::getPendingBits() const	{ return bit; }
 inline fxBool G3Decoder::seenRTC() const	{ return (RTCrow != -1); }
diff -ru ../hylafax-v4.0pl2.dist/faxd/TagLine.c++ ./faxd/TagLine.c++
--- ../hylafax-v4.0pl2.dist/faxd/TagLine.c++	Sat Feb 14 05:49:37 1998
+++ ./faxd/TagLine.c++	Sun Apr 23 19:42:05 2000
@@ -208,7 +208,7 @@
      */
     TagLineMemoryDecoder dec(buf);
     dec.setupDecoder(fillorder,  params.is2D());
-    uint16 runs[2*2432];		// run arrays for cur+ref rows
+    uint32 runs[2*2432];		// run arrays for cur+ref rows
     dec.setRuns(runs, runs+2432, w);
 
     dec.decode(NULL, w, th);		// discard decoded data
diff -ru ../hylafax-v4.0pl2.dist/faxd/choptest.c++ ./faxd/choptest.c++
--- ../hylafax-v4.0pl2.dist/faxd/choptest.c++	Sat Feb 14 05:49:45 1998
+++ ./faxd/choptest.c++	Sun Apr 23 19:43:35 2000
@@ -70,7 +70,7 @@
 }
 
 static fxBool
-isBlank(uint16* runs, u_int rowpixels)
+isBlank(uint32* runs, u_int rowpixels)
 {
     u_int x = 0;
     for (;;) {
@@ -89,7 +89,7 @@
 {
     setupDecoder(fillorder,  params.is2D());
     u_int rowpixels = params.pageWidth();	// NB: assume rowpixels <= 2432
-    uint16 runs[2*2432];			// run arrays for cur+ref rows
+    uint32 runs[2*2432];			// run arrays for cur+ref rows
     setRuns(runs, runs+2432, rowpixels);
 
     if (!RTCraised()) {
diff -ru ../hylafax-v4.0pl2.dist/faxd/cqtest.c++ ./faxd/cqtest.c++
--- ../hylafax-v4.0pl2.dist/faxd/cqtest.c++	Sat Feb 14 05:49:45 1998
+++ ./faxd/cqtest.c++	Sun Apr 23 19:43:08 2000
@@ -145,7 +145,7 @@
     setupDecoder(recvFillOrder, params.is2D());
 
     u_int rowpixels = params.pageWidth();	// NB: assume rowpixels <= 2432
-    uint16 runs[2*2432];			// run arrays for cur+ref rows
+    uint32 runs[2*2432];			// run arrays for cur+ref rows
     setRuns(runs, runs+2432, rowpixels);
 
     recvEOLCount = 0;				// count of EOL codes
diff -ru ../hylafax-v4.0pl2.dist/faxd/faxQueueApp.c++ ./faxd/faxQueueApp.c++
--- ../hylafax-v4.0pl2.dist/faxd/faxQueueApp.c++	Sat Feb 14 05:49:42 1998
+++ ./faxd/faxQueueApp.c++	Sun Apr 23 19:43:35 2000
@@ -807,7 +807,7 @@
 }
 
 static fxBool
-isBlank(uint16* runs, u_int rowpixels)
+isBlank(uint32* runs, u_int rowpixels)
 {
     u_int x = 0;
     for (;;) {
@@ -826,7 +826,7 @@
 {
     setupDecoder(fillorder,  params.is2D());
     u_int rowpixels = params.pageWidth();	// NB: assume rowpixels <= 2432
-    uint16 runs[2*2432];			// run arrays for cur+ref rows
+    uint32 runs[2*2432];			// run arrays for cur+ref rows
     setRuns(runs, runs+2432, rowpixels);
 
     if (!RTCraised()) {
diff -ru ../hylafax-v4.0pl2.dist/faxd/tagtest.c++ ./faxd/tagtest.c++
--- ../hylafax-v4.0pl2.dist/faxd/tagtest.c++	Sat Feb 14 05:49:46 1998
+++ ./faxd/tagtest.c++	Sun Apr 23 19:43:35 2000
@@ -236,7 +236,7 @@
      */
     MemoryDecoder dec(buf);
     dec.setupDecoder(fillorder,  params.is2D());
-    uint16 runs[2*2432];		// run arrays for cur+ref rows
+    uint32 runs[2*2432];		// run arrays for cur+ref rows
     dec.setRuns(runs, runs+2432, w);
 
     u_int row;
diff -ru ../hylafax-v4.0pl2.dist/faxd/tif_fax3.h ./faxd/tif_fax3.h
--- ../hylafax-v4.0pl2.dist/faxd/tif_fax3.h	Sat Feb 14 05:49:07 1998
+++ ./faxd/tif_fax3.h	Sun Apr 23 13:43:37 2000
@@ -1,8 +1,8 @@
-/* $Id: tif_fax3.h,v 1.1 1997/02/16 11:17:26 guru Rel $ */
+/* $Id: tif_fax3.h,v 1.2 1999/09/17 04:08:59 mwelles Exp $ */
 
 /*
- * Copyright (c) 1990-1996 Sam Leffler
- * Copyright (c) 1991-1996 Silicon Graphics, Inc.
+ * Copyright (c) 1990-1997 Sam Leffler
+ * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  *
  * Permission to use, copy, modify, distribute, and sell this software and 
  * its documentation for any purpose is hereby granted without fee, provided
@@ -43,7 +43,7 @@
  * The routine must have the type signature given below;
  * for example:
  *
- * fillruns(unsigned char* buf, uint16* runs, uint16* erun, uint32 lastx)
+ * fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx)
  *
  * where buf is place to set the bits, runs is the array of b&w run
  * lengths (white then black), erun is the last run in the array, and
@@ -52,7 +52,7 @@
  * data in the run array as needed (e.g. to append zero runs to bring
  * the count up to a nice multiple).
  */
-typedef	void (*TIFFFaxFillFunc)(unsigned char*, uint16*, uint16*, uint32);
+typedef	void (*TIFFFaxFillFunc)(unsigned char*, uint32*, uint32*, uint32);
 
 /*
  * The default run filler; made external for other decoders.
@@ -60,7 +60,7 @@
 #if defined(__cplusplus)
 extern "C" {
 #endif
-extern	void _TIFFFax3fillruns(unsigned char*, uint16*, uint16*, uint32);
+extern	void _TIFFFax3fillruns(unsigned char*, uint32*, uint32*, uint32);
 #if defined(__cplusplus)
 }
 #endif
@@ -84,7 +84,7 @@
 typedef struct {		/* state table entry */
 	unsigned char State;	/* see above */
 	unsigned char Width;	/* width of code in bits */
-	uint16	Param;		/* unsigned 16-bit run length in bits */
+	uint32	Param;		/* unsigned 32-bit run length in bits */
 } TIFFFaxTabEnt;
 
 extern	const TIFFFaxTabEnt TIFFFaxMainTable[];




Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services