[poppler] poppler/DCTStream.cc poppler/DCTStream.h utils/HtmlOutputDev.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Mon Apr 5 11:14:21 PDT 2010


 poppler/DCTStream.cc   |   35 ++++++++++++++---------------------
 poppler/DCTStream.h    |    5 +++--
 utils/HtmlOutputDev.cc |    4 ++--
 3 files changed, 19 insertions(+), 25 deletions(-)

New commits:
commit fc071d800cb4329a3ccf898d7bf16b4db7323ad8
Author: Albert Astals Cid <aacid at kde.org>
Date:   Mon Apr 5 19:11:26 2010 +0100

    Rework DCTStream error handling, should work better now
    
    Fixes bug 26280

diff --git a/poppler/DCTStream.cc b/poppler/DCTStream.cc
index 7c6ba70..5cbaced 100644
--- a/poppler/DCTStream.cc
+++ b/poppler/DCTStream.cc
@@ -5,7 +5,7 @@
 // This file is licensed under the GPLv2 or later
 //
 // Copyright 2005 Jeff Muizelaar <jeff at infidigm.net>
-// Copyright 2005-2009 Albert Astals Cid <aacid at kde.org>
+// Copyright 2005-2010 Albert Astals Cid <aacid at kde.org>
 // Copyright 2009 Ryszard Trojnacki <rysiek at menel.com>
 //
 //========================================================================
@@ -20,7 +20,6 @@ static boolean str_fill_input_buffer(j_decompress_ptr cinfo)
 {
   int c;
   struct str_src_mgr * src = (struct str_src_mgr *)cinfo->src;
-  if (src->abort) return FALSE;
   if (src->index == 0) {
     c = 0xFF;
     src->index++;
@@ -70,7 +69,7 @@ DCTStream::~DCTStream() {
 static void exitErrorHandler(jpeg_common_struct *error) {
   j_decompress_ptr cinfo = (j_decompress_ptr)error;
   str_src_mgr * src = (struct str_src_mgr *)cinfo->src;
-  src->abort = true;
+  longjmp(src->setjmp_buffer, 1);
 }
 
 void DCTStream::init()
@@ -86,7 +85,6 @@ void DCTStream::init()
   src.pub.next_input_byte = NULL;
   src.str = str;
   src.index = 0;
-  src.abort = false;
   current = NULL;
   limit = NULL;
   
@@ -122,7 +120,6 @@ void DCTStream::reset() {
       if (c == -1)
       {
         error(-1, "Could not find start of jpeg data");
-        src.abort = true;
         return;
       }
       if (c != 0xFF) c = 0;
@@ -139,30 +136,28 @@ void DCTStream::reset() {
     }
   }
 
-  jpeg_read_header(&cinfo, TRUE);
-  if (src.abort) return;
+  if (!setjmp(src.setjmp_buffer)) {
+    jpeg_read_header(&cinfo, TRUE);
+    jpeg_start_decompress(&cinfo);
 
-  if (!jpeg_start_decompress(&cinfo))
-  {
-    src.abort = true;
-    return;
+    row_stride = cinfo.output_width * cinfo.output_components;
+    row_buffer = cinfo.mem->alloc_sarray((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
   }
-
-  row_stride = cinfo.output_width * cinfo.output_components;
-  row_buffer = cinfo.mem->alloc_sarray((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
 }
 
 int DCTStream::getChar() {
-  if (src.abort) return EOF;
-  
   int c;
 
   if (current == limit) {
     if (cinfo.output_scanline < cinfo.output_height)
     {
-      if (!jpeg_read_scanlines(&cinfo, row_buffer, 1)) return EOF;
-      current = &row_buffer[0][0];
-      limit = &row_buffer[0][(cinfo.output_width - 1) * cinfo.output_components] + cinfo.output_components;
+      if (!setjmp(src.setjmp_buffer))
+      {
+        if (!jpeg_read_scanlines(&cinfo, row_buffer, 1)) return EOF;
+        current = &row_buffer[0][0];
+        limit = &row_buffer[0][(cinfo.output_width - 1) * cinfo.output_components] + cinfo.output_components;
+      }
+      else return EOF;
     }
     else return EOF;
   }
@@ -172,8 +167,6 @@ int DCTStream::getChar() {
 }
 
 int DCTStream::lookChar() {
-  if (src.abort) return EOF;
-  
   return *current;
 }
 
diff --git a/poppler/DCTStream.h b/poppler/DCTStream.h
index 29f8cf9..6768ff2 100644
--- a/poppler/DCTStream.h
+++ b/poppler/DCTStream.h
@@ -6,7 +6,7 @@
 //
 // Copyright 2005 Jeff Muizelaar <jeff at infidigm.net>
 // Copyright 2005 Martin Kretzschmar <martink at gnome.org>
-// Copyright 2005-2007, 2009 Albert Astals Cid <aacid at kde.org>
+// Copyright 2005-2007, 2009, 2010 Albert Astals Cid <aacid at kde.org>
 //
 //========================================================================
 
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
+#include <setjmp.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -48,7 +49,7 @@ struct str_src_mgr {
     JOCTET buffer;
     Stream *str;
     int index;
-    bool abort;
+    jmp_buf setjmp_buffer;
 };
 
 
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 6df1b7c..81f8b88 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -17,7 +17,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2005-2009 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005-2010 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2008 Kjartan Maraas <kmaraas at gnome.org>
 // Copyright (C) 2008 Boris Toloknov <tlknv at yandex.ru>
 // Copyright (C) 2008 Haruyuki Kawabe <Haruyuki.Kawabe at unisys.co.jp>
@@ -50,13 +50,13 @@
 #include "Error.h"
 #include "GfxState.h"
 #include "Page.h"
+#include "PNGWriter.h"
 #ifdef ENABLE_LIBJPEG
 #include "DCTStream.h"
 #endif
 #include "GlobalParams.h"
 #include "HtmlOutputDev.h"
 #include "HtmlFonts.h"
-#include "PNGWriter.h"
 
 int HtmlPage::pgNum=0;
 int HtmlOutputDev::imgNum=1;


More information about the poppler mailing list