Skip to content

Commit

Permalink
ROB : some attributes not copied
Browse files Browse the repository at this point in the history
fixes  py-pdf#1615

"/N" attributes wrongly ignored
  • Loading branch information
pubpub-zz committed Feb 15, 2023
1 parent 4bf3e32 commit 1f0f102
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,27 @@ def _clone(
"""
# First check if this is a chain list, we need to loop to prevent recur
if (
("/Next" not in ignore_fields and "/Next" in src)
or ("/Prev" not in ignore_fields and "/Prev" in src)
(
"/Next" not in ignore_fields
and "/Next" in src
and isinstance(src.raw_get("/Next"), IndirectObject)
)
or (
"/Prev" not in ignore_fields
and "/Prev" in src
and isinstance(src.raw_get("/Prev"), IndirectObject)
)
) or (
("/N" not in ignore_fields and "/N" in src)
or ("/V" not in ignore_fields and "/V" in src)
(
"/N" not in ignore_fields
and "/N" in src
and isinstance(src.raw_get("/N"), IndirectObject)
)
or (
"/V" not in ignore_fields
and "/V" in src
and isinstance(src.raw_get("/V"), IndirectObject)
)
):
ignore_fields = list(ignore_fields)
for lst in (("/Next", "/Prev"), ("/N", "/V")):
Expand Down Expand Up @@ -230,7 +246,7 @@ def _clone(
except Exception:
cur_obj = None
for (s, c) in objs:
c._clone(s, pdf_dest, force_duplicate, ignore_fields + [k])
c._clone(s, pdf_dest, force_duplicate, ignore_fields)

for k, v in src.items():
if k not in ignore_fields:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,3 +1044,21 @@ def test_cloning(caplog):
obj21 = obj20.clone(writer, ignore_fields=None)
assert "/Test" in obj21
assert isinstance(obj21.get("/Test2"), IndirectObject)


@pytest.mark.external
def test_iss1615():
"""
test cases where /N is not indicating chains of objects
"""
url = "https://github.com/py-pdf/pypdf/files/10671366/graph_letter.pdf"
name = "graph_letter.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
writer = PdfWriter()
writer.append(reader)
assert (
"/N"
in writer.pages[0]["/Annots"][0]
.get_object()["/AP"]["/N"]["/Resources"]["/ColorSpace"]["/Cs1"][1]
.get_object()
)

0 comments on commit 1f0f102

Please sign in to comment.