[Libreoffice-commits] mso-dumper.git: doc-dump.py src/docstream.py test/doc

Miklos Vajna vmiklos at kemper.freedesktop.org
Wed Aug 28 09:15:24 PDT 2013


 doc-dump.py                 |    2 ++
 src/docstream.py            |   17 ++++++++++++++++-
 test/doc/pass/abi6272-1.doc |binary
 3 files changed, 18 insertions(+), 1 deletion(-)

New commits:
commit 8b46eda0f0f44e9499fe70875e1d6270afc8448f
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Aug 28 17:39:54 2013 +0200

    GsfDOCFile: handle errors from gsf_infile_msole_new()

diff --git a/doc-dump.py b/doc-dump.py
index b99d6fe..7279a34 100755
--- a/doc-dump.py
+++ b/doc-dump.py
@@ -23,6 +23,8 @@ class DOCDumper:
         file.close()
         dirnames = strm.getDirectoryNames()
         print '<?xml version="1.0"?>\n<streams ole-type="%s">' % strm.getName()
+        if strm.error:
+            print '<error what="%s"/>' % strm.error
         for dirname in dirnames:
             if len(dirname) == 0 or dirname in ['Root Entry']:
                 continue
diff --git a/src/docstream.py b/src/docstream.py
index 89cd0d7..d7afe4c 100644
--- a/src/docstream.py
+++ b/src/docstream.py
@@ -12,6 +12,7 @@ from docdirstream import DOCDirStream
 import docrecord
 import globals
 import sys
+import os
 import bisect
 
 class DOCFile:
@@ -20,6 +21,7 @@ class DOCFile:
         self.chars = chars
         self.size = len(self.chars)
         self.params = params
+        self.error = None
 
         if ord(self.chars[0]) == 0xD0 and ord(self.chars[1]) == 0xCF and ord(self.chars[2]) == 0x11 and ord(self.chars[3]) == 0xE0:
             self.initWW8()
@@ -65,11 +67,24 @@ class GsfDOCFile(DOCFile):
         self.gsf = gsf
         DOCFile.__init__(self, chars, params)
 
+    def disableStderr(self):
+        nil = os.open(os.devnull, os.O_WRONLY)
+        self.savedStderr = os.dup(2)
+        os.dup2(nil, 2)
+
+    def enableStderr(self):
+        os.dup2(self.savedStderr, 2)
+
     def initWW8(self):
         self.streams = {}
         self.gsf.gsf_init()
         gsfInput = self.gsf.gsf_input_memory_new(self.chars, len(self.chars), False)
-        gsfInfile = self.gsf.gsf_infile_msole_new(gsfInput)
+        self.disableStderr()
+        gsfInfile = self.gsf.gsf_infile_msole_new(gsfInput, None)
+        self.enableStderr()
+        if not gsfInfile:
+            self.error = "gsf_infile_msole_new() failed"
+            return
         for i in range(self.gsf.gsf_infile_num_children(gsfInfile)):
             child = self.gsf.gsf_infile_child_by_index(gsfInfile, i)
             childName = ctypes.string_at(self.gsf.gsf_infile_name_by_index(gsfInfile,i))
diff --git a/test/doc/pass/abi6272-1.doc b/test/doc/pass/abi6272-1.doc
new file mode 100644
index 0000000..2172872
Binary files /dev/null and b/test/doc/pass/abi6272-1.doc differ


More information about the Libreoffice-commits mailing list