Skip to content

Commit 5a5887a

Browse files
committed
Handle sloppy cross references more and less generically
A previous commit adjusted readSymbol() to skip leading whitespace in order to avoid errors with sloppy cross references. This did not fix handling of literals such as numbers and booleans in readObject() because they're not accessed using readSymbol(). Also, adjusting the very low-level readSymbol() function might generate fallout. So instead, this change moves the skipping of leading whitespace into readObject() so that it affects all types of referenced objects equally but not all symbol lookups altogether. Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
1 parent f50847f commit 5a5887a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

peepdf/PDFCore.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7857,6 +7857,11 @@ def readObject(self, content, objectType=None, forceMode=False, looseMode=False)
78577857
pdfObject = None
78587858
oldCounter = self.charCounter
78597859
self.charCounter = 0
7860+
# skip leading whitespace in case of sloppy reference offsets
7861+
self.readSpaces(content)
7862+
if self.charCounter > 0:
7863+
content = content[self.charCounter:]
7864+
self.charCounter = 0
78607865
if objectType is not None:
78617866
objectsTypeArray = [self.delimiters[i][2] for i in range(len(self.delimiters))]
78627867
index = objectsTypeArray.index(objectType)
@@ -8011,7 +8016,6 @@ def readSymbol(self, string, symbol, deleteSpaces=True):
80118016
errorMessage = 'EOF while looking for symbol "'+symbol+'"'
80128017
pdfFile.addError(errorMessage)
80138018
return (-1, errorMessage)
8014-
self.readSpaces(string)
80158019
while string[self.charCounter] == '%':
80168020
ret = self.readUntilEndOfLine(string)
80178021
if ret[0] == -1:

0 commit comments

Comments
 (0)