mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 09:39:58 -04:00
Add a mod's BYML key offsets in size_t, so an offset near 4 GiB no longer passes the bounds check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,8 +73,10 @@ static int scale_sensitivity(uint8_t *p, size_t n, float k, float was[8]) {
|
||||
if (!u32_at(p, n, root + 4 + 8 * (size_t)i, &e) || (e & 0xffffff) >= nkeys ||
|
||||
!u32_at(p, n, keys + 4 + 4 * (size_t)(e & 0xffffff), &at))
|
||||
return 0;
|
||||
const char *name = (const char *)p + keys + at;
|
||||
if (keys + at + sizeof "StickSensitivity" > n || strcmp(name, "StickSensitivity")) continue;
|
||||
// in size_t: a mod's key offset near 2^32 would wrap the 32-bit sum below n
|
||||
if ((size_t)keys + at + sizeof "StickSensitivity" > n) continue;
|
||||
const char *name = (const char *)p + (size_t)keys + at;
|
||||
if (strcmp(name, "StickSensitivity")) continue;
|
||||
if (e >> 24 != 0xc0 || !u32_at(p, n, root + 8 + 8 * (size_t)i, &arr) || !u32_at(p, n, arr, &ah) ||
|
||||
(ah & 0xff) != 0xc0)
|
||||
return 0;
|
||||
|
||||
@@ -208,9 +208,9 @@ static int u32_at(const Byml *b, size_t off, uint32_t *v) {
|
||||
static const char *key_name(const Byml *b, uint32_t k) {
|
||||
uint32_t head, at;
|
||||
if (!u32_at(b, b->keys, &head) || (head & 0xff) != 0xc2 || k >= head >> 8 || !u32_at(b, b->keys + 4 + 4 * k, &at) ||
|
||||
b->keys + at >= b->n || !memchr(b->p + b->keys + at, 0, b->n - b->keys - at))
|
||||
return NULL;
|
||||
return (const char *)b->p + b->keys + at;
|
||||
(size_t)b->keys + at >= b->n || !memchr(b->p + (size_t)b->keys + at, 0, b->n - ((size_t)b->keys + at)))
|
||||
return NULL; // in size_t: a mod's table offset near 2^32 would wrap the 32-bit sum below n
|
||||
return (const char *)b->p + (size_t)b->keys + at;
|
||||
}
|
||||
|
||||
// The offset of the value of hash node `node`'s entry `name`, which must have type `type`; 0 when there is none.
|
||||
|
||||
Reference in New Issue
Block a user