Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f64165

Browse files
committed
TST: add a check that the hinting factor is greater than 0
If you pass 0 it will cause a divide by 0 error and kill Python.
1 parent 755b8ff commit 8f64165

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/matplotlib/tests/test_font_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,11 @@ def test_fallback_errors():
360360
TypeError, match="Fallback fonts must be FT2Font objects."
361361
):
362362
ft2font.FT2Font(file_name, _fallback_list=[0])
363+
364+
365+
def test_ft2font_positive_hinting_factor():
366+
file_name = findfont('DejaVu Sans')
367+
with pytest.raises(
368+
ValueError, match="hinting_factor must be greater than 0"
369+
):
370+
ft2font.FT2Font(file_name, 0)

src/ft2font_wrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ static int PyFT2Font_init(PyFT2Font *self, PyObject *args, PyObject *kwds)
362362
&hinting_factor, &fallback_list, &kerning_factor)) {
363363
return -1;
364364
}
365+
if (hinting_factor <= 0) {
366+
PyErr_SetString(PyExc_ValueError,
367+
"hinting_factor must be greater than 0");
368+
goto exit;
369+
}
365370

366371
self->stream.base = NULL;
367372
self->stream.size = 0x7fffffff; // Unknown size.

0 commit comments

Comments
 (0)