]> xmof Git - DeDRM.git/commitdiff
PDF: Ignore invalid objid in non-strict mode, fixes #233
authorNoDRM <no_drm123@protonmail.com>
Thu, 29 Dec 2022 18:52:08 +0000 (19:52 +0100)
committerNoDRM <no_drm123@protonmail.com>
Thu, 29 Dec 2022 18:52:08 +0000 (19:52 +0100)
DeDRM_plugin/ineptpdf.py

index ea509ad4c80725f9a1ce291e51f180930599d597..ab4813030958dac91bed90fed839e838e32a26dd 100755 (executable)
@@ -1831,7 +1831,19 @@ class PDFDocument(object):
                 try:
                     obj = objs[i]
                 except IndexError:
-                    raise PDFSyntaxError('Invalid object number: objid=%r' % (objid))
+                    # This IndexError used to just raise an exception.
+                    # Unfortunately that seems to break some PDFs, see this issue:
+                    # https://github.com/noDRM/DeDRM_tools/issues/233
+                    # I'm not sure why this is the case, but lets try only raising that exception
+                    # when in STRICT mode, and make it a warning otherwise.
+                    if STRICT:
+                        raise PDFSyntaxError('Invalid object number: objid=%r' % (objid))
+
+                    print('Invalid object number: objid=%r' % (objid))
+                    print("Continuing anyways?")
+                    print("If the resulting PDF is corrupted, please open a bug report.")
+                    return None
+
                 if isinstance(obj, PDFStream):
                     obj.set_objid(objid, 0)
             else: