msodumper/binarystream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
New commits: commit 0ffc7eac2596ff590eb7c7612940c7d785fea167 Author: Hossein <[email protected]> AuthorDate: Thu Sep 2 20:12:41 2021 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Sep 3 13:59:32 2021 +0200 Handling exception on invalid values of the fields There are situations where a field has an invalid value. In such a case, an exception is occurs, the program halts execution, and the output will be incomplete. With this fix, if a key is not found for the dict, name="INVALID" will be use in the output XML. This is an example execution for attachment 171572 from tdf#142021 , "EMF with PolyfillMode set to 0 before the bottom star record" PolygonFillMode can be either 1 or 2, but the field value has the value of 0. PolygonFillMode = { 0x01: "ALTERNATE", 0x02: "WINDING" } $ /opt/libreoffice7.2/program/python ./emf-dump.py star_pfm0.emf Traceback (most recent call last): File "./emf-dump.py", line 29, in <module> main(sys.argv) File "./emf-dump.py", line 25, in main dumper.dump() File "./emf-dump.py", line 20, in dump strm.dump() File "msodumper/emfrecord.py", line 76, in dump handler.dump() File "msodumper/emfrecord.py", line 400, in dump self.printAndSet("PolygonFillMode", self.readuInt32(), dict=PolygonFillMode) File "msodumper/binarystream.py", line 32, in printAndSet attrs += ' name="%s"' % dict[value] KeyError: 0 Change-Id: Id965ba0c47eace3029dd5fa12266f1a144eee41e Reviewed-on: https://gerrit.libreoffice.org/c/mso-dumper/+/121529 Tested-by: Miklos Vajna <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/msodumper/binarystream.py b/msodumper/binarystream.py index bdd8f37..4946a45 100644 --- a/msodumper/binarystream.py +++ b/msodumper/binarystream.py @@ -29,7 +29,7 @@ class BinaryStream: attrs = "" if dict: if value in dict or default is None: - attrs += ' name="%s"' % dict[value] + attrs += ' name="%s"' % dict.get(value, "INVALID") else: attrs += ' name="%s"' % default if hexdump and type(value) != float:
