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

Ignore path constructors that do not begin with m #749

Merged
merged 2 commits into from
May 6, 2022
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed

- Ignoring (invalid) path constructors that do not begin with `m` ([#749](https://github.com/pdfminer/pdfminer.six/pull/749))

## [20220506]

### Fixed

- `IndexError` when handling invalid bfrange code map in
CMap ([#731](https://github.com/pdfminer/pdfminer.six/pull/731))
- `TypeError` in lzw.py when `self.table` is not set ([#732](https://github.com/pdfminer/pdfminer.six/pull/732))
Expand Down
11 changes: 10 additions & 1 deletion pdfminer/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ def paint_path(
"""Paint paths described in section 4.4 of the PDF reference manual"""
shape = "".join(x[0] for x in path)

if shape.count("m") > 1:
if shape[:1] != "m":
# Per PDF Reference Section 4.4.1, "path construction operators may
# be invoked in any sequence, but the first one invoked must be m
# or re to begin a new subpath." Since pdfminer.six already
# converts all `re` (rectangle) operators to their equivelent
# `mlllh` representation, paths ingested by `.paint_path(...)` that
# do not begin with the `m` operator are invalid.
pass

elif shape.count("m") > 1:
# recurse if there are multiple m's in this shape
for m in re.finditer(r"m[^m]+", shape):
subpath = path[m.start(0) : m.end(0)]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ def parse(path):
(71.41, 434.89),
]

def test_paint_path_without_starting_m(self):
gs = PDFGraphicState()
analyzer = self._get_analyzer()
analyzer.cur_item = LTContainer([0, 100, 0, 100])
paths = [[("h",)], [("l", 72.41, 433.89), ("l", 82.41, 433.89), ("h",)]]
for path in paths:
analyzer.paint_path(gs, False, False, False, path)
assert len(analyzer.cur_item._objs) == 0


class TestBinaryDetector:
def test_stringio(self):
Expand Down