summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2017-11-16 12:51:11 +0000
committerCaolán McNamara <caolanm@redhat.com>2017-11-16 14:47:31 +0100
commite94988dd8c21e18bf45c52365c9a7f56655c7e59 (patch)
treee5b79834a38f0003aa38de0a1185735b15412ab7 /vcl/source
parentf7ffc93bf6f2693454c7ac5fdaff06b1caa63a6e (diff)
ofz#3002 set a limit to how broken a jpeg is to give up recovering
take ImageMagicks 1000 warnings as the starting point Change-Id: Id685764404d27b151daf031a4860055f64dd0915 Reviewed-on: https://gerrit.libreoffice.org/44818 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/filter/jpeg/jpegc.cxx20
1 files changed, 20 insertions, 0 deletions
diff --git a/vcl/source/filter/jpeg/jpegc.cxx b/vcl/source/filter/jpeg/jpegc.cxx
index a7e400263fd1..ede057805b72 100644
--- a/vcl/source/filter/jpeg/jpegc.cxx
+++ b/vcl/source/filter/jpeg/jpegc.cxx
@@ -38,6 +38,8 @@ extern "C" {
#include <vcl/bitmapaccess.hxx>
#include <vcl/graphicfilter.hxx>
+#define WarningLimit 1000
+
#ifdef _MSC_VER
#pragma warning(push, 1) /* disable to __declspec(align()) aligned warning */
#pragma warning (disable: 4324)
@@ -69,6 +71,23 @@ extern "C" void outputMessage (j_common_ptr cinfo)
SAL_WARN("vcl.filter", "failure reading JPEG: " << buffer);
}
+extern "C" void emitMessage (j_common_ptr cinfo, int msg_level)
+{
+ if (msg_level < 0)
+ {
+ // ofz#3002 try to retain some degree of recoverability up to some
+ // reasonable limit (initially using ImageMagick's current limit of
+ // 1000), then bail.
+ // https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf
+ if (cinfo->err->num_warnings++ > WarningLimit)
+ cinfo->err->error_exit(cinfo);
+ else
+ cinfo->err->output_message(cinfo);
+ }
+ else if (cinfo->err->trace_level >= msg_level)
+ cinfo->err->output_message(cinfo);
+}
+
class JpegDecompressOwner
{
public:
@@ -125,6 +144,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines,
cinfo.err = jpeg_std_error( &jerr.pub );
jerr.pub.error_exit = errorExit;
jerr.pub.output_message = outputMessage;
+ jerr.pub.emit_message = emitMessage;
jpeg_create_decompress( &cinfo );
aOwner.set(&cinfo);