[vector] Fix NULL write in hb_pdf_get_resources under OOM

hb_pdf_get_resources stashes a heap-allocated hb_pdf_resources_t
pointer into the reused paint->defs vector.  It called
paint->defs.resize(sizeof(void*)) and ignored the return value,
then memcpy'd into paint->defs.arrayZ.  Under failing-malloc
(reached by the fuzzer), resize can fail leaving arrayZ as nullptr,
and the subsequent memcpy dereferences NULL.

Check the resize result.  On failure, destruct + free the
already-constructed resources struct and return nullptr — which
all callers of hb_pdf_get_resources already handle.

Found by the OSS-Fuzz hb-vector-fuzzer after the prior commit
that enabled PDF-format fuzzing.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad Esfahbod committed 2026-04-13 02:17:36 -06:00
1 parent 4c94a812b0
commit 891cb21c7b
1 file changed
+6 -1
+6 -1
View File
@@ -247,7 +247,12 @@ hb_pdf_get_resources (hb_vector_paint_t *paint)
auto *res = (hb_pdf_resources_t *) hb_calloc (1, sizeof (hb_pdf_resources_t));
if (unlikely (!res)) return nullptr;
new (res) hb_pdf_resources_t ();
paint->defs.resize (sizeof (void *));
if (unlikely (!paint->defs.resize (sizeof (void *))))
{
res->~hb_pdf_resources_t ();
hb_free (res);
return nullptr;
}
memcpy (paint->defs.arrayZ, &res, sizeof (void *));
}
hb_pdf_resources_t *res;