Skip to content
Open
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
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_ft2font.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ def enc(name):
# Though the encoding is different, the glyph should be the same.
assert unic[u] == armn[m]

# Out-of-range charmap indices must be rejected rather than indexing out of
# bounds. A negative index previously passed the upper-bound-only check and
# read face->charmaps[i] out of bounds.
with pytest.raises(RuntimeError, match='exceeds the available number'):
font.set_charmap(-1)
with pytest.raises(RuntimeError, match='exceeds the available number'):
font.set_charmap(font.num_charmaps)


_expected_sfnt_names = {
'DejaVu Sans': {
Expand Down
2 changes: 1 addition & 1 deletion src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void FT2Font::_set_transform(

void FT2Font::set_charmap(int i)
{
if (i >= face->num_charmaps) {
if (i < 0 || i >= face->num_charmaps) {
throw std::runtime_error("i exceeds the available number of char maps");
}
FT_CHECK(FT_Set_Charmap, face, face->charmaps[i]);
Expand Down
Loading