Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid configuration for mediabox_params in PDFPage class. #1081

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Cache pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fuzz-seconds: 800
output-sarif: true
- name: Upload Crash
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
Expand Down
12 changes: 8 additions & 4 deletions pdfminer/pdfpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from pdfminer.pdfexceptions import PDFObjectNotFound, PDFValueError
from pdfminer.pdfparser import PDFParser
from pdfminer.pdftypes import dict_value, int_value, list_value, resolve1
from pdfminer.pdftypes import PDFObjRef, dict_value, int_value, list_value, resolve1
from pdfminer.psparser import LIT
from pdfminer.utils import parse_rect

Expand Down Expand Up @@ -67,9 +67,13 @@ def __init__(
self.resources: Dict[object, object] = resolve1(
self.attrs.get("Resources", dict()),
)
mediabox_params: List[Any] = [
resolve1(mediabox_param) for mediabox_param in self.attrs["MediaBox"]
]
mediabox_params: List[Any] = []
if isinstance(self.attrs["MediaBox"], PDFObjRef):
mediabox_params = resolve1(self.attrs["MediaBox"])
else:
mediabox_params = [
resolve1(mediabox_param) for mediabox_param in self.attrs["MediaBox"]
]
self.mediabox = parse_rect(resolve1(mediabox_params))
self.cropbox = self.mediabox
if "CropBox" in self.attrs:
Expand Down
Binary file added samples/annotations.pdf
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/test_pdfdocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pdfminer.pdfdocument import PDFDocument, PDFNoPageLabels
from pdfminer.pdfexceptions import PDFObjectNotFound
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfparser import PDFParser
from pdfminer.pdftypes import dict_value, int_value
from tests.helpers import absolute_sample_path
Expand Down Expand Up @@ -49,3 +50,11 @@ def test_no_page_labels(self):

with pytest.raises(PDFNoPageLabels):
doc.get_page_labels()

def test_annotations(self):
path = absolute_sample_path("annotations.pdf")
with open(path, "rb") as fp:
parser = PDFParser(fp)
doc = PDFDocument(parser)
for i, page in enumerate(PDFPage.create_pages(doc)):
print(page)
Loading