} else {
if (jpscan == 0x1) params.jp = JP_GREY;
else if (jpscan & 0x2) params.jp = JP_COLOR;
+ /*
+ * ITU T.30 does not specify that bits 16 (MR) or 31 (MMR) must be set to zero if color fax is used;
+ * and ITU T.32 Table 21 provides a data field, "JP", for JPEG support separate from "DF" for data
+ * format and does not specify that DF is meaningless in DCS when JP is used; but because T.4/T.6
+ * (MH/MR/MMR), JBIG, and JPEG are distinct formats from each other, we must conclude that any
+ * indication of JPEG in DCS must, therefore, invalidate any indication in DCS of MH/MR/MMR/JBIG.
+ * Otherwise, having both df and jp be non-zero will be confusing and possibly cause problems.
+ */
+ if (params.jp != JP_NONE) params.df = 0; // Yes, this is DF_1DMH, but there is no "DF_NONE".
}
return (true);
} else {
#include <ctype.h>
#define RCVBUFSIZ (32*1024) // XXX
+#define COLORBUFSIZ (2000*1024) // 1MB is not big enough
static void setupCompression(TIFF*, u_int, u_int, uint32);
* rather fax-specific.
*/
recvEOLCount = 0;
- recvRow = (u_char*) malloc(1024*1000); // 1M should do it?
+ recvRow = (u_char*) malloc(COLORBUFSIZ);
fxAssert(recvRow != NULL, "page buffering error (JPEG page).");
recvPageStart = recvRow;
}
if (params.df == DF_JBIG) {
flushRawData(tif, 0, (const u_char*) buf, cc);
} else {
- memcpy(recvRow, (const char*) buf, cc);
- recvRow += cc;
+ /* We don't support reception of a JPEG page bigger than COLORBUFSIZ. */
+ if (recvRow + cc - recvPageStart > COLORBUFSIZ) cc = recvPageStart + COLORBUFSIZ - recvRow;
+ if (cc > 0) {
+ memcpy(recvRow, (const char*) buf, cc);
+ recvRow += cc;
+ }
}
} while (!fin);
if (params.df == DF_JBIG) clearSDNORMCount();
case JP_GREY+4:
case JP_COLOR+4:
recvEOLCount = 0;
- recvRow = (u_char*) malloc(1024*1000); // 1M should do it?
+ recvRow = (u_char*) malloc(COLORBUFSIZ);
fxAssert(recvRow != NULL, "page buffering error (JPEG page).");
recvPageStart = recvRow;
setupStartPage(tif, params);
}
break;
}
- if (params.jp != JP_GREY && params.jp != JP_COLOR) {
- flushRawData(tif, 0, (const u_char*) buf, cc);
- } else {
- memcpy(recvRow, (const char*) buf, cc);
- recvRow += cc;
- }
- if (seq & 2 && (params.jp == JP_GREY || params.jp == JP_COLOR)) {
- fixupJPEG(tif);
+ switch (dataform) {
+ case JP_GREY+4:
+ case JP_COLOR+4:
+ /* We don't support reception of a JPEG page bigger than COLORBUFSIZ. */
+ if (recvRow + cc - recvPageStart > COLORBUFSIZ) cc = recvPageStart + COLORBUFSIZ - recvRow;
+ if (cc > 0) {
+ memcpy(recvRow, (const char*) buf, cc);
+ recvRow += cc;
+ }
+ if (seq & 2) fixupJPEG(tif);
+ break;
+ default:
+ flushRawData(tif, 0, (const u_char*) buf, cc);
+ break;
}
}
if (dcs_caps.isBitEnabled(FaxParams::BITNUM_FULLCOLOR)) {
if (jp == JP_GREY) jp = JP_COLOR;
}
+ /*
+ * ITU T.30 does not specify that bits 16 (MR) or 31 (MMR) must be set to zero if color fax is used;
+ * and ITU T.32 Table 21 provides a data field, "JP", for JPEG support separate from "DF" for data
+ * format and does not specify that DF is meaningless in DCS when JP is used; but because T.4/T.6
+ * (MH/MR/MMR), JBIG, and JPEG are distinct formats from each other, we must conclude that any
+ * indication of JPEG in DCS must, therefore, invalidate any indication in DCS of MH/MR/MMR/JBIG.
+ * Otherwise, having both df and jp be non-zero will be confusing and possibly cause problems.
+ */
+ if (jp != JP_NONE) df = 0; // Yes, this is DF_1DMH, but there is no "DF_NONE".
if (ec == EC_DISABLE &&
(df == DF_2DMMR || df == DF_JBIG || jp == JP_GREY || jp == JP_COLOR)) {
// MMR, JBIG, and JPEG require ECM... we've seen cases where fax