From 891cb21c7b84da769b3753ad804eb77ba8f69233 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 13 Apr 2026 02:17:36 -0600 Subject: [PATCH] [vector] Fix NULL write in hb_pdf_get_resources under OOM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/hb-vector-paint-pdf.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index d956714b3..81e54e29a 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -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;