From 71a35aa4963c569f4b1dd1530c19ea622df19a8e Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Fri, 27 Mar 2020 19:40:02 +0100 Subject: [PATCH] Reproduce crash on Windows? (#37) 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. --- src/uharfbuzz/_harfbuzz.pyx | 2 ++ tests/test_uharfbuzz.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/uharfbuzz/_harfbuzz.pyx b/src/uharfbuzz/_harfbuzz.pyx index 33d796d..654062f 100644 --- a/src/uharfbuzz/_harfbuzz.pyx +++ b/src/uharfbuzz/_harfbuzz.pyx @@ -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) diff --git a/tests/test_uharfbuzz.py b/tests/test_uharfbuzz.py index e58e00e..cb122ef 100644 --- a/tests/test_uharfbuzz.py +++ b/tests/test_uharfbuzz.py @@ -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 @@ -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)