diff --git a/poppler/DCTStream.cc b/poppler/DCTStream.cc index 6302c8b..396ad2a 100644 --- a/poppler/DCTStream.cc +++ b/poppler/DCTStream.cc @@ -60,9 +60,20 @@ static void str_term_source(j_decompress_ptr cinfo) { } -DCTStream::DCTStream(Stream *strA, int colorXformA) : +DCTStream::DCTStream(Stream *strA, int colorXformA, Object *dict) : FilterStream(strA) { colorXform = colorXformA; + if (dict != NULL) { + Object obj; + + dict->dictLookup("Width", &obj); + err.width = (obj.isInt() && obj.getInt() <= JPEG_MAX_DIMENSION) ? obj.getInt() : 0; + obj.free(); + dict->dictLookup("Height", &obj); + err.height = (obj.isInt() && obj.getInt() <= JPEG_MAX_DIMENSION) ? obj.getInt() : 0; + obj.free(); + } else + err.height = err.width = 0; init(); } @@ -74,7 +85,12 @@ DCTStream::~DCTStream() { static void exitErrorHandler(jpeg_common_struct *error) { j_decompress_ptr cinfo = (j_decompress_ptr)error; str_error_mgr * err = (struct str_error_mgr *)cinfo->err; - longjmp(err->setjmp_buffer, 1); + if (cinfo->err->msg_code == JERR_IMAGE_TOO_BIG && err->width != 0 && err->height != 0) { + cinfo->image_height = err->height; + cinfo->image_width = err->width; + } else { + longjmp(err->setjmp_buffer, 1); + } } void DCTStream::init() diff --git a/poppler/DCTStream.h b/poppler/DCTStream.h index 55bd985..07f6c95 100644 --- a/poppler/DCTStream.h +++ b/poppler/DCTStream.h @@ -43,6 +43,7 @@ extern "C" { #include +#include } struct str_src_mgr { @@ -55,12 +56,14 @@ struct str_src_mgr { struct str_error_mgr { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer; + int width; + int height; }; class DCTStream: public FilterStream { public: - DCTStream(Stream *strA, int colorXformA); + DCTStream(Stream *strA, int colorXformA, Object *dict); virtual ~DCTStream(); virtual StreamKind getKind() { return strDCT; } virtual void reset(); diff --git a/poppler/Stream.cc b/poppler/Stream.cc index fa050e1..6ff3318 100644 --- a/poppler/Stream.cc +++ b/poppler/Stream.cc @@ -181,7 +181,7 @@ Stream *Stream::addFilters(Object *dict, int recursion) { dict->dictLookup("DP", ¶ms); } if (obj.isName()) { - str = makeFilter(obj.getName(), str, ¶ms, recursion); + str = makeFilter(obj.getName(), str, ¶ms, recursion, dict); } else if (obj.isArray()) { for (i = 0; i < obj.arrayGetLength(); ++i) { obj.arrayGet(i, &obj2); @@ -207,7 +207,7 @@ Stream *Stream::addFilters(Object *dict, int recursion) { return str; } -Stream *Stream::makeFilter(char *name, Stream *str, Object *params, int recursion) { +Stream *Stream::makeFilter(char *name, Stream *str, Object *params, int recursion, Object *dict) { int pred; // parameters int colors; int bits; @@ -308,7 +308,7 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params, int recursio } obj.free(); } - str = new DCTStream(str, colorXform); + str = new DCTStream(str, colorXform, dict); } else if (!strcmp(name, "FlateDecode") || !strcmp(name, "Fl")) { pred = 1; columns = 1; diff --git a/poppler/Stream.h b/poppler/Stream.h index 3d48f92..7581d04 100644 --- a/poppler/Stream.h +++ b/poppler/Stream.h @@ -226,7 +226,7 @@ private: virtual GBool hasGetChars() { return false; } virtual int getChars(int nChars, Guchar *buffer); - Stream *makeFilter(char *name, Stream *str, Object *params, int recursion = 0); + Stream *makeFilter(char *name, Stream *str, Object *params, int recursion = 0, Object *dict = NULL); int ref; // reference count #if MULTITHREADED