Make hb_sanitize_context_t::max_ops unsigned #2079
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently
max_ops
inhb_sanitize_context_t
is signed, but in...::start_processing
an unsigned value is assigned:If
this->end - this->start
is big enough, then(this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR
can not be represented in a signedint
and the assignment overflows, leading to negative values inmax_ops
. Of course, then a font will no longer load correctly. There are at least two possible fixes for this: Just makemax_ops
unsigned (negative values don't make sense there anyway and the comparisons with0
are written such that they still work with unsigned values) or usehb_min((unsigned) HB_SANITIVE_MAX_OPS_MAX, ...)
before assigning to->max_ops
to provide an upper bound for the value.I used the first approach here because I wasn't sure if
max_ops
should be limited toHB_SANITIVE_MAX_OPS_MAX
or if that constant only has meaning for special fonts.The original issue had appeared in latex3/luaotfload#126 but can be reproduced without LuaTeX:
Download SourceHanNotoCJK.ttc from https://github.com/adobe-fonts/source-han-super-otc/releases (~390MiB) and try
On my system this gives only a collection of GID 0 glyphs:
the same font in
hb-view
giveshb-view: FT_New_Memory_Face fail
.