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 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-08 09:24:37 -05:00
parent b8d7eede08
commit 8647f19370

View File

@@ -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);
}