@@ -1760,7 +1760,7 @@ def test_repair_root(caplog):
1760
1760
caplog .clear ()
1761
1761
reader = PdfReader (
1762
1762
BytesIO (
1763
- b .replace (b"/Root 1 0 R" , b"/Root 2 0 R" ).replace (b"/Catalog" , b"/Catalo " )
1763
+ b .replace (b"/Root 1 0 R" , b"/Root 2 0 R" ).replace (b"/Catalog/Pages 3 0 R " , b"/Catalo " )
1764
1764
)
1765
1765
)
1766
1766
with pytest .raises (PdfReadError ):
@@ -1775,9 +1775,9 @@ def test_repair_root(caplog):
1775
1775
1776
1776
# Invalid /Root Entry + error in get_object
1777
1777
caplog .clear ()
1778
- b = b .replace (b"/Root 1 0 R" , b"/Root 2 0 R" ).replace (b"/Catalog" , b"/Catalo " )
1779
- b = b [:5124 ] + b"A" + b [5125 :]
1780
- reader = PdfReader (BytesIO (b ))
1778
+ data = b .replace (b"/Root 1 0 R" , b"/Root 2 0 R" ).replace (b"/Catalog/Pages 3 0 R " , b"/Catalo " )
1779
+ data = data [:5124 ] + b"A" + data [5125 :]
1780
+ reader = PdfReader (BytesIO (data ))
1781
1781
with pytest .raises (PdfReadError ):
1782
1782
len (reader .pages )
1783
1783
assert all (
@@ -1788,6 +1788,23 @@ def test_repair_root(caplog):
1788
1788
)
1789
1789
)
1790
1790
1791
+ # Invalid /Root Entry without /Type, but /Pages.
1792
+ caplog .clear ()
1793
+ reader = PdfReader (
1794
+ BytesIO (
1795
+ b .replace (b"/Root 1 0 R" , b"/Root 2 0 R" ).replace (b"/Catalog" , b"/Catalo " )
1796
+ )
1797
+ )
1798
+ assert len (reader .pages ) == 1
1799
+ assert all (
1800
+ msg in caplog .text
1801
+ for msg in (
1802
+ "Invalid Root object in trailer" ,
1803
+ 'Searching object with "/Catalog" key' ,
1804
+ f"Possible root found at IndirectObject(2, 0, { id (reader )} ), but missing /Catalog key"
1805
+ )
1806
+ )
1807
+
1791
1808
1792
1809
@pytest .mark .enable_socket
1793
1810
def test_issue3151 (caplog ):
0 commit comments