From 8647f193707259c0d307a614db615b84100f3fa3 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Sun, 8 Nov 2026 09:24:37 -0500 Subject: [PATCH] Check that a texture's packaged data fits its memory pool before copying it in. nvnTextureInitialize copied the layout's size of packaged data to the pool's memory at the texture's offset without checking either against the pool: a descriptor larger than its pool wrote past the pool's storage. It now stops with the sizes instead. Co-Authored-By: Claude Opus 5.5 --- runtime/nvn_api_obj.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index bb2e3546..2cd6d7a6 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -221,6 +221,12 @@ NVN_API(nvnTextureInitialize) { if (s->pkg_data) { if (!o->mem || nvn_gpu_only((uintptr_t)o->mem)) rt_fatal("nvn: packaged texture data without CPU-visible storage"); + // the layout's size from the game's descriptor, against the pool it is copied into (its host storage may span + // more than its size): a heap overrun otherwise + uint64_t room = s->pool->span > s->pool->size ? s->pool->span : s->pool->size; + if (s->off < 0 || (uint64_t)s->off > room || o->L.size > room - (uint64_t)s->off) + rt_fatal("nvn: packaged texture data of %#llx bytes at %#llx does not fit its pool (%#llx bytes)", + (unsigned long long)o->L.size, (unsigned long long)s->off, (unsigned long long)room); memcpy(o->mem, s->pkg_data, (size_t)o->L.size); nvn_guest_written((uintptr_t)o->mem, o->L.size); }