Browse Source

split_pgp_file: add workaround for large packets breaking split

Fabian Peter Hammerle 1 year ago
parent
commit
e28f2d4c3d
1 changed files with 16 additions and 2 deletions
  1. 16 2
      profile_default/startup/init.py

+ 16 - 2
profile_default/startup/init.py

@@ -1,6 +1,7 @@
 import itertools
 import pathlib
 import typing
+import warnings
 
 import numpy
 import pandas
@@ -46,8 +47,21 @@ def split_pgp_file(
         bundle = pgpdump.BinaryData(bundle_bytes)
     remaining_bytes = bundle.data
     for packet in bundle.packets():
-        prefix, remaining_bytes = remaining_bytes.split(packet.data, maxsplit=1)
-
+        try:
+            prefix, remaining_bytes = remaining_bytes.split(packet.data, maxsplit=1)
+        except ValueError:
+            assert len(packet.data) > 596  # actual threshold might be higher
+            split_index = 2 ** 9
+            prefix, remaining_bytes = remaining_bytes.split(
+                packet.data[:split_index], maxsplit=1
+            )
+            separator, remaining_bytes = remaining_bytes.split(
+                packet.data[split_index:], maxsplit=1
+            )
+            assert sum(separator) == len(packet.data) - split_index
+            warnings.warn(
+                "ignoring separator; output of join_pgp_packets will be invalid"
+            )
         yield prefix
         yield packet
     assert not remaining_bytes