summaryrefslogtreecommitdiff
path: root/libmwaw/libmwaw-infinite-loop.patch.1
blob: 9c8e3a8b413ecf0868a6b61563f89ae97d794069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fix infinite loop in findCentralDirectoryEnd

WPXSvInputStreamImpl::seek returns -1 if it catches an exception

--- libmwaw/src/lib/MWAWZipStream.cxx	2013-06-18 00:37:57.208657845 +0200
+++ libmwaw/src/lib/MWAWZipStream.cxx	2013-06-18 00:48:20.971665257 +0200
@@ -258,18 +258,20 @@
 
 static bool findCentralDirectoryEnd(WPXInputStream *input)
 {
-  input->seek(0, WPX_SEEK_SET);
+  // seek returns -1 both on error and on seek to position post-the-end
+  int ret = input->seek(0, WPX_SEEK_SET);
   try {
-    while (!input->atEOS())
-      input->seek(1024, WPX_SEEK_CUR);
+    while (-1 != ret && !input->atEOS())
+      ret = input->seek(1024, WPX_SEEK_CUR);
     input->seek(-1024, WPX_SEEK_CUR);
-    while (!input->atEOS()) {
+    ret = 0; // perhaps it's smaller than 1024?
+    while (-1 != ret && !input->atEOS()) {
       unsigned signature = getInt(input);
       if (signature == CDIR_END_SIG) {
         input->seek(-4, WPX_SEEK_CUR);
         return true;
       } else
-        input->seek(-3, WPX_SEEK_CUR);
+        ret = input->seek(-3, WPX_SEEK_CUR);
     }
   } catch (...) {
     return false;