Skip to content

Commit

Permalink
Check if newobj is not None in indirect sweep.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Karvonen committed Jun 28, 2022
1 parent bdfbc92 commit 16393f5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions PyPDF2/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,13 +869,16 @@ def _sweep_indirect_references(
if newobj is None:
try:
newobj = data.pdf.get_object(data)
hash_value = newobj.hash_value()
hash_value = None
if newobj is not None:
hash_value = newobj.hash_value()
# Check if object is already added to pdf.
if hash_value in self._idnum_hash:
return IndirectObject(self._idnum_hash[hash_value], 0, self)
self._objects.append(None) # placeholder
idnum = len(self._objects)
self._idnum_hash[hash_value] = idnum
if hash_value is not None:
self._idnum_hash[hash_value] = idnum
newobj_ido = IndirectObject(idnum, 0, self)
if data.pdf not in extern_map:
extern_map[data.pdf] = {}
Expand Down

0 comments on commit 16393f5

Please sign in to comment.