[subset] Fix fuzzer timeout.

Fixes https://oss-fuzz.com/testcase-detail/5979721620652032. Timeout was caused by degenerate map insert behaviour due to poor integer hash function. Presize the map to avoid it. Also fixes collect_mapping() for cmap format 13.
pull/4243/head
Garret Rieger 2 years ago committed by Behdad Esfahbod
parent 208c9490cb
commit a652281ed6
  1. 13
      src/hb-ot-cmap-table.hh
  2. BIN
      test/fuzzing/fonts/clusterfuzz-testcase-hb-subset-fuzzer-5979721620652032

@ -757,8 +757,7 @@ struct CmapSubtableLongSegmented
hb_codepoint_t gid = this->groups[i].glyphID;
if (!gid)
{
/* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */
if (! T::group_get_glyph (this->groups[i], end)) continue;
if (T::formatNumber == 13) continue;
start++;
gid++;
}
@ -766,11 +765,13 @@ struct CmapSubtableLongSegmented
if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs))
end = start + (hb_codepoint_t) num_glyphs - gid;
mapping->resize (mapping->get_population () + end - start + 1);
for (unsigned cp = start; cp <= end; cp++)
{
unicodes->add (cp);
mapping->set (cp, gid);
gid++;
gid += T::increment;
}
}
}
@ -794,6 +795,9 @@ struct CmapSubtableLongSegmented
struct CmapSubtableFormat12 : CmapSubtableLongSegmented<CmapSubtableFormat12>
{
static constexpr int increment = 1;
static constexpr int formatNumber = 12;
static hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group,
hb_codepoint_t u)
{ return likely (group.startCharCode <= group.endCharCode) ?
@ -866,6 +870,9 @@ struct CmapSubtableFormat12 : CmapSubtableLongSegmented<CmapSubtableFormat12>
struct CmapSubtableFormat13 : CmapSubtableLongSegmented<CmapSubtableFormat13>
{
static constexpr int increment = 0;
static constexpr int formatNumber = 13;
static hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group,
hb_codepoint_t u HB_UNUSED)
{ return group.glyphID; }

Loading…
Cancel
Save