Skip to content

Commit

Permalink
Find end-of-text marker correctly
Browse files Browse the repository at this point in the history
When modifying annotation appearance streams, finding the PDF end-of-text marker b"ET" must be the last one in the stream. I.e. use rfind(b"ET") instead of find(b"ET").
We erroneously searched for the next one - which can destroy the stream if it happens to contain multiple b"ET" strings.
  • Loading branch information
JorjMcKie committed Mar 26, 2024
1 parent 8e32ba1 commit c83d623
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ def color_string(cs, code):

if annot_type == mupdf.PDF_ANNOT_FREE_TEXT:
BT = ap.find(b"BT")
ET = ap.find(b"ET") + 2
ET = ap.rfind(b"ET") + 2
ap = ap[BT:ET]
w, h = self.rect.width, self.rect.height
if rotate in (90, 270) or not (apnmat.b == apnmat.c == 0):
Expand Down Expand Up @@ -7382,7 +7382,7 @@ def _add_freetext_annot(
#%pythonappend _add_freetext_annot
ap = val._getAP()
BT = ap.find(b"BT")
ET = ap.find(b"ET") + 2
ET = ap.rfind(b"ET") + 2
ap = ap[BT:ET]
w = rect[2]-rect[0]
h = rect[3]-rect[1]
Expand Down

0 comments on commit c83d623

Please sign in to comment.