mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 07:09:57 -04:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user