Fail jpeg decodes on too many progressive scans
authorMatt Sarett <msarett@google.com>
Tue, 8 Nov 2016 20:26:56 +0000 (15:26 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 8 Nov 2016 21:39:15 +0000 (21:39 +0000)
BUG:642462

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4560

Change-Id: I22891ce1e0b3a1bedefc34dadd5cf34dfc301b79
Reviewed-on: https://skia-review.googlesource.com/4560
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Matt Sarett <msarett@google.com>

resources/invalid_images/many-progressive-scans.jpg [new file with mode: 0644]
src/codec/SkJpegDecoderMgr.cpp
src/codec/SkJpegDecoderMgr.h
tests/CodecTest.cpp

diff --git a/resources/invalid_images/many-progressive-scans.jpg b/resources/invalid_images/many-progressive-scans.jpg
new file mode 100644 (file)
index 0000000..05a1a00
Binary files /dev/null and b/resources/invalid_images/many-progressive-scans.jpg differ
index 70401c0..c2837aa 100644 (file)
@@ -25,6 +25,17 @@ static void output_message(j_common_ptr info) {
     print_message(info, "output_message");
 }
 
+static void progress_monitor(j_common_ptr info) {
+  int scan = ((j_decompress_ptr)info)->input_scan_number;
+  // Progressive images with a very large number of scans can cause the
+  // decoder to hang.  Here we use the progress monitor to abort on
+  // a very large number of scans.  100 is arbitrary, but much larger
+  // than the number of scans we might expect in a normal image.
+  if (scan >= 100) {
+      skjpeg_err_exit(info);
+  }
+}
+
 bool JpegDecoderMgr::returnFalse(const char caller[]) {
     print_message((j_common_ptr) &fDInfo, caller);
     return false;
@@ -71,6 +82,8 @@ void JpegDecoderMgr::init() {
     fInit = true;
     fDInfo.src = &fSrcMgr;
     fDInfo.err->output_message = &output_message;
+    fDInfo.progress = &fProgressMgr;
+    fProgressMgr.progress_monitor = &progress_monitor;
 }
 
 JpegDecoderMgr::~JpegDecoderMgr() {
index 7bc422d..272c5b4 100644 (file)
@@ -68,6 +68,7 @@ private:
     jpeg_decompress_struct fDInfo;
     skjpeg_source_mgr      fSrcMgr;
     skjpeg_error_mgr       fErrorMgr;
+    jpeg_progress_mgr      fProgressMgr;
     bool                   fInit;
 };
 
index 32ad959..dacabca 100644 (file)
@@ -1439,4 +1439,5 @@ DEF_TEST(Codec_InvalidImages, r) {
     // ASAN will complain if there is an issue.
     test_invalid_images(r, "invalid_images/int_overflow.ico", false);
     test_invalid_images(r, "invalid_images/skbug5887.gif", true);
+    test_invalid_images(r, "invalid_images/many-progressive-scans.jpg", false);
 }