[poppler] 3 commits - poppler/Stream.cc utils/pdfsig.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jun 24 16:47:22 UTC 2018


 poppler/Stream.cc |   28 +++++++++++-----------------
 utils/pdfsig.cc   |    5 ++++-
 2 files changed, 15 insertions(+), 18 deletions(-)

New commits:
commit 267228bb071016621c80fc8514927905164aaeea
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Jun 24 18:28:22 2018 +0200

    pdfsig: Use posix basename() instead of GNU one
    
    So it builds on non GNU systems too
    
    Bug #106783

diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc
index c4e52fd8..592270ad 100644
--- a/utils/pdfsig.cc
+++ b/utils/pdfsig.cc
@@ -23,6 +23,7 @@
 #include <time.h>
 #include <hasht.h>
 #include <fstream>
+#include <libgen.h>
 #include "parseargs.h"
 #include "Object.h"
 #include "Array.h"
@@ -104,7 +105,9 @@ static void dumpSignature(int sig_num, int sigCount, FormWidgetSignature *sig_wi
     // since { is the magic character to replace things we need to put it twice where
     // we don't want it to be replaced
     GooString *format = GooString::format("{{0:s}}.sig{{1:{0:d}d}}", sigCountLength);
-    GooString *path = GooString::format(format->getCString(), basename(filename), sig_num);
+    char *filenameCopy = strdup(filename);
+    GooString *path = GooString::format(format->getCString(), basename(filenameCopy), sig_num);
+    free(filenameCopy);
     printf("Signature #%d (%u bytes) => %s\n", sig_num, signature->getLength(), path->getCString());
     std::ofstream outfile(path->getCString(), std::ofstream::binary);
     outfile.write(signature->getCString(), signature->getLength());
commit 459f369145a9d8f638fe123425f0e2880487640e
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Jun 24 11:51:20 2018 +0200

    Move variable declarations closer to where they are used
    
    Allows for declaring two of them as const

diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index f43c3ef9..2c55f295 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -499,12 +499,6 @@ GBool ImageStream::getPixel(Guchar *pix) {
 }
 
 Guchar *ImageStream::getLine() {
-  Gulong buf, bitMask;
-  int bits;
-  int c;
-  int i;
-  Guchar *p;
-
   if (unlikely(inputLine == nullptr)) {
       return nullptr;
   }
@@ -512,9 +506,9 @@ Guchar *ImageStream::getLine() {
   int readChars = str->doGetChars(inputLineSize, inputLine);
   for ( ; readChars < inputLineSize; readChars++) inputLine[readChars] = EOF;
   if (nBits == 1) {
-    p = inputLine;
-    for (i = 0; i < nVals; i += 8) {
-      c = *p++;
+    Guchar *p = inputLine;
+    for (int i = 0; i < nVals; i += 8) {
+      const int c = *p++;
       imgLine[i+0] = (Guchar)((c >> 7) & 1);
       imgLine[i+1] = (Guchar)((c >> 6) & 1);
       imgLine[i+2] = (Guchar)((c >> 5) & 1);
@@ -531,17 +525,17 @@ Guchar *ImageStream::getLine() {
     // we assume a component fits in 8 bits, with this hack
     // we treat 16 bit images as 8 bit ones until it's fixed correctly.
     // The hack has another part on GfxImageColorMap::GfxImageColorMap
-    p = inputLine;
-    for (i = 0; i < nVals; ++i) {
+    Guchar *p = inputLine;
+    for (int i = 0; i < nVals; ++i) {
       imgLine[i] = *p++;
       p++;
     }
   } else {
-    bitMask = (1 << nBits) - 1;
-    buf = 0;
-    bits = 0;
-    p = inputLine;
-    for (i = 0; i < nVals; ++i) {
+    const Gulong bitMask = (1 << nBits) - 1;
+    Gulong buf = 0;
+    int bits = 0;
+    Guchar *p = inputLine;
+    for (int i = 0; i < nVals; ++i) {
       while (bits < nBits) {
 	buf = (buf << 8) | (*p++ & 0xff);
 	bits += 8;
commit e8b82c4239da638ae77dfab07faaff33af4af1cc
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Jun 24 11:46:36 2018 +0200

    ImageStream::getLine: Fix ubsan undefined shift
    
    I'm not totally sure this is the "correct" fix, but doesn't regress
    any file on my test suite so seems one of those cases only happens
    on bad files, and this helps oss-fuzz progress in its testing
    
    Fixes oss-fuzz/8432

diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 21bd3b9b..f43c3ef9 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -504,7 +504,7 @@ Guchar *ImageStream::getLine() {
   int c;
   int i;
   Guchar *p;
-  
+
   if (unlikely(inputLine == nullptr)) {
       return nullptr;
   }
@@ -542,7 +542,7 @@ Guchar *ImageStream::getLine() {
     bits = 0;
     p = inputLine;
     for (i = 0; i < nVals; ++i) {
-      if (bits < nBits) {
+      while (bits < nBits) {
 	buf = (buf << 8) | (*p++ & 0xff);
 	bits += 8;
       }


More information about the poppler mailing list