[repack] fix new node bounds.

This commit is contained in:
Garret Rieger 2022-07-20 03:26:29 +00:00
parent c20b85cfed
commit 5babfda3f2
4 changed files with 17 additions and 4 deletions

View File

@ -653,6 +653,7 @@ struct graph_t
clone->obj.tail = tail; clone->obj.tail = tail;
clone->distance = 0; clone->distance = 0;
clone->space = 0; clone->space = 0;
printf("Creating new node from %p to %p\n", head, tail);
unsigned clone_idx = vertices_.length - 2; unsigned clone_idx = vertices_.length - 2;

View File

@ -104,8 +104,9 @@ struct Lookup : public OT::Lookup
unsigned type = lookupType; unsigned type = lookupType;
unsigned extension_size = OT::ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>::static_size; unsigned extension_size = OT::ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>::static_size;
unsigned start = buffer.length; unsigned start = buffer.length;
unsigned end = start + extension_size; unsigned end = start + extension_size - 1;
if (!buffer.resize (buffer.length + extension_size)) if (!buffer.resize (buffer.length + extension_size))
// TODO: resizing potentially invalidates existing head/tail pointers.
return false; return false;
OT::ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>* extension = OT::ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>* extension =

View File

@ -205,6 +205,7 @@ inline hb_blob_t* serialize (const graph_t& graph)
{ {
hb_vector_t<char> buffer; hb_vector_t<char> buffer;
size_t size = graph.total_size_in_bytes (); size_t size = graph.total_size_in_bytes ();
printf("Expected graph size: %lu.\n", size);
if (!buffer.alloc (size)) { if (!buffer.alloc (size)) {
DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to allocate output buffer."); DEBUG_MSG (SUBSET_REPACK, nullptr, "Unable to allocate output buffer.");
return nullptr; return nullptr;

View File

@ -44,7 +44,7 @@ using graph::graph_t;
*/ */
static inline static inline
void _make_extensions (hb_tag_t table_tag, graph_t& sorted_graph, hb_vector_t<char>& buffer) bool _make_extensions (hb_tag_t table_tag, graph_t& sorted_graph, hb_vector_t<char>& buffer)
{ {
// TODO: Move this into graph or gsubgpos graph? // TODO: Move this into graph or gsubgpos graph?
hb_hashmap_t<unsigned, graph::Lookup*> lookups; hb_hashmap_t<unsigned, graph::Lookup*> lookups;
@ -52,8 +52,10 @@ void _make_extensions (hb_tag_t table_tag, graph_t& sorted_graph, hb_vector_t<ch
for (auto p : lookups.iter ()) for (auto p : lookups.iter ())
{ {
p.second->make_extension (table_tag, sorted_graph, p.first, buffer); if (!p.second->make_extension (table_tag, sorted_graph, p.first, buffer))
return false;
} }
return true;
} }
static inline static inline
@ -175,6 +177,8 @@ hb_resolve_overflows (const T& packed,
printf("Resolving overflows!\n"); printf("Resolving overflows!\n");
graph_t sorted_graph (packed); graph_t sorted_graph (packed);
sorted_graph.sort_shortest_distance (); sorted_graph.sort_shortest_distance ();
printf("Initial graph size: %lu.\n",
sorted_graph.total_size_in_bytes ());
bool will_overflow = graph::will_overflow (sorted_graph); bool will_overflow = graph::will_overflow (sorted_graph);
if (!will_overflow) if (!will_overflow)
@ -183,11 +187,17 @@ hb_resolve_overflows (const T& packed,
} }
hb_vector_t<char> extension_buffer; hb_vector_t<char> extension_buffer;
if (!extension_buffer.alloc(100000)) // TODO: cleanup
return nullptr;
if ((table_tag == HB_OT_TAG_GPOS if ((table_tag == HB_OT_TAG_GPOS
|| table_tag == HB_OT_TAG_GSUB) || table_tag == HB_OT_TAG_GSUB)
&& will_overflow) && will_overflow)
{ {
_make_extensions (table_tag, sorted_graph, extension_buffer); if (!_make_extensions (table_tag, sorted_graph, extension_buffer)) {
printf("make extensions failed.\n");
return nullptr;
}
DEBUG_MSG (SUBSET_REPACK, nullptr, "Assigning spaces to 32 bit subgraphs."); DEBUG_MSG (SUBSET_REPACK, nullptr, "Assigning spaces to 32 bit subgraphs.");
if (sorted_graph.assign_spaces ()) if (sorted_graph.assign_spaces ())
sorted_graph.sort_shortest_distance (); sorted_graph.sort_shortest_distance ();