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

Loading…
Cancel
Save