- dsp->runs = (uint32*) _TIFFmalloc(nruns*sizeof (uint16));
- if (dsp->runs == NULL) {
- TIFFError("Fax3SetupState",
- "%s: No space for Group 3/4 run arrays",
- tif->tif_name);
- return (0);
- }
- dsp->curruns = dsp->runs;
- if (needsRefLine)
- dsp->refruns = dsp->runs + (nruns>>1);
- else
- dsp->refruns = NULL;
- if (is2DEncoding(dsp)) { /* NB: default is 1D routine */
- tif->tif_decoderow = Fax3Decode2D;
- tif->tif_decodestrip = Fax3Decode2D;
- tif->tif_decodetile = Fax3Decode2D;
- }
- } else if (needsRefLine) { /* 2d encoding */
- Fax3EncodeState* esp = EncoderState(tif);
+ nruns = needsRefLine ? 2*TIFFroundup(rowpixels,32) : rowpixels;
+
+ dsp->runs = (uint32*) CheckMalloc(tif, 2*nruns+3, sizeof (uint32),
+ "for Group 3/4 run arrays");
+ if (dsp->runs == NULL)
+ return (0);
+ dsp->curruns = dsp->runs;
+ if (needsRefLine)
+ dsp->refruns = dsp->runs + (nruns>>1);
+ else
+ dsp->refruns = NULL;
+ if (is2DEncoding(dsp)) { /* NB: default is 1D routine */
+ tif->tif_decoderow = Fax3Decode2D;
+ tif->tif_decodestrip = Fax3Decode2D;
+ tif->tif_decodetile = Fax3Decode2D;
+ }
+
+ if (needsRefLine) { /* 2d encoding */
+ Fax3CodecState* esp = EncoderState(tif);