[Libreoffice-commits] .: src/docrecord.py src/docstream.py
Miklos Vajna
vmiklos at kemper.freedesktop.org
Mon May 13 08:32:23 PDT 2013
src/docrecord.py | 19 +++++++++++++++++++
src/docstream.py | 27 +++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
New commits:
commit fafba58deed9279de410dadcb0fb9eb8c303014e
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Mon May 13 17:27:53 2013 +0200
doc: do not crash on RC4 encrypted documents, print a todo instead
diff --git a/src/docrecord.py b/src/docrecord.py
index f79cd9b..caeb48f 100644
--- a/src/docrecord.py
+++ b/src/docrecord.py
@@ -1766,6 +1766,25 @@ class Dop2007(DOCDirStream):
self.pos += 34
print '</dop2007>'
+class RC4EncryptionHeader(DOCDirStream):
+ """The encryption header structure used for RC4 encryption."""
+ def __init__(self, fib, pos, size):
+ DOCDirStream.__init__(self, fib.doc.getDirectoryStreamByName("1Table").bytes)
+ self.fib = fib
+ self.pos = pos
+ self.size = size
+
+ def dump(self):
+ print '<RC4EncryptionHeader>'
+ self.Salt = self.readBytes(16)
+ print '<Salt value="%s"/>' % globals.encodeName(self.Salt)
+ self.EncryptedVerifier = self.readBytes(16)
+ print '<EncryptedVerifier value="%s"/>' % globals.encodeName(self.EncryptedVerifier)
+ self.EncryptedVerifierHash = self.readBytes(16)
+ print '<EncryptedVerifierHash value="%s"/>' % globals.encodeName(self.EncryptedVerifierHash)
+ print '</RC4EncryptionHeader>'
+ assert self.pos == self.size
+
class Dop(DOCDirStream):
"""The Dop structure contains the document and compatibility settings for the document."""
def __init__(self, fib):
diff --git a/src/docstream.py b/src/docstream.py
index 0e939db..195c0e4 100644
--- a/src/docstream.py
+++ b/src/docstream.py
@@ -57,7 +57,9 @@ class WordDocumentStream(DOCDirStream):
def dumpFib(self):
print '<fib>'
- self.dumpFibBase("base")
+ if not self.dumpFibBase("base"):
+ print '</fib>'
+ return
self.printAndSet("csw", self.readuInt16())
self.dumpFibRgW97("fibRgW")
self.printAndSet("cslw", self.readuInt16())
@@ -112,6 +114,7 @@ class WordDocumentStream(DOCDirStream):
print '</%s>' % name
def dumpFibBase(self, name):
+ ret = True
print '<%s type="FibBase" size="32 bytes">' % name
self.printAndSet("wIdent", self.readuInt16())
@@ -139,7 +142,26 @@ class WordDocumentStream(DOCDirStream):
self.printAndSet("fObfuscated", self.getBit(buf, 15))
self.printAndSet("nFibBack", self.readuInt16())
- self.printAndSet("lKey", self.readuInt32())
+
+ if self.fEncrypted == 1 and self.fObfuscated == 0:
+ self.printAndSet("lKey", self.readuInt32(), end = False)
+ print '<EncryptionVersionInfo>'
+ tableStream = self.doc.getDirectoryStreamByName("1Table")
+ self.printAndSet("vMajor", tableStream.readuInt16())
+ self.printAndSet("vMinor", tableStream.readuInt16())
+ print '</EncryptionVersionInfo>'
+ if self.vMajor == 0x0001 and self.vMinor == 0x0001:
+ docrecord.RC4EncryptionHeader(self, tableStream.pos, self.lKey).dump()
+ print '<todo what="handle RC4 encryption"/>'
+ elif self.vMajor in (0x0002, 0x0003, 0x0004) and self.vMinor == 0x0002:
+ print '<todo what="handle RC4CryptoApiEncryptionHeader"/>'
+ else:
+ print '<todo what="unexpected vMajor %d and vMinor %d"/>' % (self.vMajor, self.vMinor)
+ print '</lKey>'
+ ret = False
+ else:
+ self.printAndSet("lKey", self.readuInt32())
+
self.printAndSet("envr", self.readuInt8())
buf = self.readuInt8()
@@ -157,6 +179,7 @@ class WordDocumentStream(DOCDirStream):
self.printAndSet("reserved6", self.readuInt32())
print '</%s>' % name
+ return ret
def dumpFibRgW97(self, name):
print '<%s type="FibRgW97" size="28 bytes">' % name
More information about the Libreoffice-commits
mailing list