Commit 19fd108e for libheif

commit 19fd108e6e8d82ad3e1853d945a809ad3fbd5669
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Sat Sep 5 00:42:29 2026 +0200

    Replace alloca with std::vector in the Emscripten item-ID helpers (GHSA-vg7w-rp49-4fc2)

    heif_js_context_get_list_of_top_level_image_IDs and
    heif_js_context_get_list_of_item_IDs sized an alloca() from the item
    count. With the default 64 KB WebAssembly stack and no stack-overflow
    check, a file with enough items (~16000) overflowed the shadow stack
    into the static data segment and permanently trapped the module
    instance, so every later call (including heif_get_version) aborted.

    Use std::vector<heif_item_id>, matching the idiom already used in
    heif_cxx.h. This also removes the dead 'if (!ids)' null check (alloca
    never returns null) and the incorrect free() of stack memory.

    Part of GHSA-vg7w-rp49-4fc2 (Emscripten build only).

diff --git a/libheif/api/libheif/heif_emscripten.h b/libheif/api/libheif/heif_emscripten.h
index 76b07ff8..370a4e18 100644
--- a/libheif/api/libheif/heif_emscripten.h
+++ b/libheif/api/libheif/heif_emscripten.h
@@ -92,19 +92,9 @@ static emscripten::val heif_js_context_get_list_of_top_level_image_IDs(
     return result;
   }

-  heif_item_id* ids = (heif_item_id*) alloca(count * sizeof(heif_item_id));
-  if (!ids) {
-    struct heif_error err;
-    err.code = heif_error_Memory_allocation_error;
-    err.subcode = heif_suberror_Security_limit_exceeded;
-    return emscripten::val(err);
-  }
+  std::vector<heif_item_id> ids(static_cast<size_t>(count));

-  int received = heif_context_get_list_of_top_level_image_IDs(context, ids, count);
-  if (!received) {
-    free(ids);
-    return result;
-  }
+  int received = heif_context_get_list_of_top_level_image_IDs(context, ids.data(), count);

   for (int i = 0; i < received; i++) {
     result.set(i, ids[i]);
@@ -126,15 +116,9 @@ static emscripten::val heif_js_context_get_list_of_item_IDs(
     return result;
   }

-  heif_item_id* ids = (heif_item_id*) alloca(count * sizeof(heif_item_id));
-  if (!ids) {
-    struct heif_error err;
-    err.code = heif_error_Memory_allocation_error;
-    err.subcode = heif_suberror_Security_limit_exceeded;
-    return emscripten::val(err);
-  }
+  std::vector<heif_item_id> ids(static_cast<size_t>(count));

-  int num_ids_received = heif_context_get_list_of_item_IDs(context, ids, count);
+  int num_ids_received = heif_context_get_list_of_item_IDs(context, ids.data(), count);

   for (int i = 0; i < num_ids_received; i++) {
     result.set(i, ids[i]);