76f8c5
From e2a8d2c149988a96fec0dc0ec38001091cd9061e Mon Sep 17 00:00:00 2001
76f8c5
From: Jason Crain <jason@aquaticape.us>
76f8c5
Date: Fri, 19 Dec 2014 01:56:45 -0600
76f8c5
Subject: [PATCH] Move array reallocation from visitLine to startLine
76f8c5
76f8c5
Fixes potential memory corruption from writing after end of lines
76f8c5
array.
76f8c5
76f8c5
https://bugs.freedesktop.org/show_bug.cgi?id=84555
76f8c5
---
76f8c5
 poppler/TextOutputDev.cc | 10 +++++-----
76f8c5
 1 file changed, 5 insertions(+), 5 deletions(-)
76f8c5
76f8c5
diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
76f8c5
index 4b7ff40..9ed955e 100644
76f8c5
--- a/poppler/TextOutputDev.cc
76f8c5
+++ b/poppler/TextOutputDev.cc
76f8c5
@@ -4072,6 +4072,11 @@ void TextSelectionDumper::startLine()
76f8c5
 
76f8c5
 void TextSelectionDumper::finishLine()
76f8c5
 {
76f8c5
+  if (nLines == linesSize) {
76f8c5
+    linesSize *= 2;
76f8c5
+    lines = (GooList **)grealloc(lines, linesSize * sizeof(GooList *));
76f8c5
+  }
76f8c5
+
76f8c5
   if (words && words->getLength() > 0)
76f8c5
     lines[nLines++] = words;
76f8c5
   else if (words)
76f8c5
@@ -4088,11 +4093,6 @@ void TextSelectionDumper::visitLine (TextLine *line,
76f8c5
 {
76f8c5
   TextLineFrag frag;
76f8c5
 
76f8c5
-  if (nLines == linesSize) {
76f8c5
-    linesSize *= 2;
76f8c5
-    lines = (GooList **)grealloc(lines, linesSize * sizeof(GooList *));
76f8c5
-  }
76f8c5
-
76f8c5
   frag.init(line, edge_begin, edge_end - edge_begin);
76f8c5
 
76f8c5
   if (tableId >= 0 && frag.line->blk->tableId < 0) {
76f8c5
-- 
76f8c5
2.1.3
76f8c5