mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-26 01:11:25 +01:00
[instancer] Treat a zero-size pool allocation as success in gvar instancing
hb_alloc_pool_t::alloc(0) legitimately returns nullptr while no shared chunk is open, but hb_vector_t::allocate_from_pool() took any nullptr as an allocation failure and flagged the (empty) vector with set_error(). The next allocate_from_pool() on it then tripped assert(!length && !allocated), aborting hb-subset during partial instancing of a crafted ~1 KB variable font whose retained glyph has more than 16,376 points (so no small request ever opens the shared chunk) and whose tuple is split by the requested axis range. Fix the root cause where the vector already special-cases zero-size requests on the heap path: a null result is a failure only when bytes were requested (size && !arrayZ). tuple_delta_t::copy_from() also discarded the results of its seven duplicate_vector_from_pool() calls, so a genuine pool failure during a tuple clone would reach the same assert (or silently drop gvar under NDEBUG); it now returns bool, change_tuple_var_axis_limit() marks out in error, and change_tuple_variations_axis_limits() fails instead of continuing. A regression test for the zero-size pool allocation is added to src/test-vector.cc. The attack font now instances to the same output as the control; test-vector and the subset suite pass. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-N0R68QRI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
88e5077a80
commit
d73f4eea07
3 files changed
+33
-10
No files matched your search
+17
-9
@@ -320,16 +320,17 @@ struct tuple_delta_t
|
||||
return *this;
|
||||
}
|
||||
|
||||
void copy_from (const tuple_delta_t& o, hb_alloc_pool_t *pool = nullptr)
|
||||
bool copy_from (const tuple_delta_t& o, hb_alloc_pool_t *pool = nullptr)
|
||||
{
|
||||
axis_tuples = o.axis_tuples;
|
||||
indices.duplicate_vector_from_pool (pool, o.indices);
|
||||
deltas_x.duplicate_vector_from_pool (pool, o.deltas_x);
|
||||
deltas_y.duplicate_vector_from_pool (pool, o.deltas_y);
|
||||
compiled_tuple_header.duplicate_vector_from_pool (pool, o.compiled_tuple_header);
|
||||
compiled_deltas.duplicate_vector_from_pool (pool, o.compiled_deltas);
|
||||
compiled_peak_coords.duplicate_vector_from_pool (pool, o.compiled_peak_coords);
|
||||
compiled_interm_coords.duplicate_vector_from_pool (pool, o.compiled_interm_coords);
|
||||
return !axis_tuples.in_error () &&
|
||||
indices.duplicate_vector_from_pool (pool, o.indices) &&
|
||||
deltas_x.duplicate_vector_from_pool (pool, o.deltas_x) &&
|
||||
deltas_y.duplicate_vector_from_pool (pool, o.deltas_y) &&
|
||||
compiled_tuple_header.duplicate_vector_from_pool (pool, o.compiled_tuple_header) &&
|
||||
compiled_deltas.duplicate_vector_from_pool (pool, o.compiled_deltas) &&
|
||||
compiled_peak_coords.duplicate_vector_from_pool (pool, o.compiled_peak_coords) &&
|
||||
compiled_interm_coords.duplicate_vector_from_pool (pool, o.compiled_interm_coords);
|
||||
}
|
||||
|
||||
void remove_axis (hb_tag_t axis_tag)
|
||||
@@ -427,7 +428,13 @@ struct tuple_delta_t
|
||||
|
||||
tuple_delta_t new_var;
|
||||
if (i < solutions.length - 1)
|
||||
new_var.copy_from (*this, pool);
|
||||
{
|
||||
if (unlikely (!new_var.copy_from (*this, pool)))
|
||||
{
|
||||
out.ensure_error ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
new_var = std::move (*this);
|
||||
|
||||
@@ -1158,6 +1165,7 @@ struct TupleVariationData
|
||||
{
|
||||
// This may move var out.
|
||||
var.change_tuple_var_axis_limit (axis_tag, *axis_limit, axis_triple_distances, out, scratch, pool);
|
||||
if (unlikely (out.in_error ())) return false;
|
||||
if (!out) continue;
|
||||
|
||||
unsigned new_len = new_vars.length + out.length;
|
||||
|
||||
+2
-1
@@ -638,7 +638,8 @@ struct hb_vector_t
|
||||
{
|
||||
assert (!length && !allocated);
|
||||
arrayZ = (Type *) allocator->alloc (size * sizeof (Type), alignof (Type));
|
||||
if (unlikely (!arrayZ))
|
||||
/* The pool returns nullptr for a zero-size request; that is not a failure. */
|
||||
if (unlikely (size && !arrayZ))
|
||||
{
|
||||
set_error ();
|
||||
return false;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "hb.hh"
|
||||
#include "hb-vector.hh"
|
||||
#include "hb-alloc-pool.hh"
|
||||
#include "hb-set.hh"
|
||||
#include "hb-map.hh"
|
||||
#include <string>
|
||||
@@ -314,5 +315,18 @@ main (int argc, char **argv)
|
||||
v.push (m);
|
||||
}
|
||||
|
||||
/* An empty allocation from a pool with no open chunk is not a failure. */
|
||||
{
|
||||
hb_alloc_pool_t pool;
|
||||
hb_vector_t<int> v, empty;
|
||||
hb_always_assert (v.allocate_from_pool (&pool, 0));
|
||||
hb_always_assert (!v.in_error ());
|
||||
hb_always_assert (v.duplicate_vector_from_pool (&pool, empty));
|
||||
hb_always_assert (!v.in_error ());
|
||||
hb_always_assert (v.allocate_from_pool (&pool, 2));
|
||||
hb_always_assert (!v.in_error ());
|
||||
hb_always_assert (v.length == 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user