[poppler] fofi/FoFiIdentifier.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Thu May 24 19:16:17 UTC 2018


 fofi/FoFiIdentifier.cc |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

New commits:
commit 07318f3899248f67a58148b29a9555ff47a1b083
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu May 24 20:15:42 2018 +0200

    StreamReader::cmp: Fix potential undefined behaviour
    
    going outside an array range is technically undefined behaviour,
    even if then after you go back in range with the next operation, so
    we first calculate the diff and then add it to the array

diff --git a/fofi/FoFiIdentifier.cc b/fofi/FoFiIdentifier.cc
index 3d41145b..ffe9c47c 100644
--- a/fofi/FoFiIdentifier.cc
+++ b/fofi/FoFiIdentifier.cc
@@ -378,13 +378,12 @@ GBool StreamReader::getUVarBE(int pos, int size, Guint *val) {
 }
 
 GBool StreamReader::cmp(int pos, const char *s) {
-  int n;
-
-  n = (int)strlen(s);
+  const int n = (int)strlen(s);
   if (!fillBuf(pos, n)) {
     return gFalse;
   }
-  return !memcmp(buf - bufPos + pos, s, n);
+  const int posDiff = pos - bufPos;
+  return !memcmp(buf + posDiff, s, n);
 }
 
 GBool StreamReader::fillBuf(int pos, int len) {


More information about the poppler mailing list