Skip to content

Commit

Permalink
Reproduce crash on Windows? (#37)
Browse files Browse the repository at this point in the history
Keep a reference to the data blob to avoid HB looking at GC-ed memory. This avoids bad gids and crashes in some environments if the user code doesn't hold on to the blob itself.
  • Loading branch information
justvanrossum authored Mar 27, 2020
1 parent 541174d commit 71a35aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,12 @@ cdef hb_blob_t* _reference_table_func(
cdef class Face:
cdef hb_face_t* _hb_face
cdef object _reference_table_func
cdef object _blob

def __cinit__(self, bytes blob, int index=0):
cdef hb_blob_t* hb_blob
if blob is not None:
self._blob = blob
hb_blob = hb_blob_create(
blob, len(blob), HB_MEMORY_MODE_READONLY, NULL, NULL)
self._hb_face = hb_face_create(hb_blob, index)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_uharfbuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


TESTDATA = Path(__file__).parent / "data"
ADOBE_BLANK_TTF = (TESTDATA / "AdobeBlank.subset.ttf").read_bytes()
ADOBE_BLANK_TTF_PATH = TESTDATA / "AdobeBlank.subset.ttf"


@pytest.fixture
Expand All @@ -22,7 +22,7 @@ def blankfont():
{gid=8, name="u1F4A9", code=0x1F4A9}, # PILE OF POO
]
"""
face = hb.Face(ADOBE_BLANK_TTF)
face = hb.Face(ADOBE_BLANK_TTF_PATH.read_bytes())
font = hb.Font(face)
upem = face.upem
font.scale = (upem, upem)
Expand Down

0 comments on commit 71a35aa

Please sign in to comment.