diff --git a/runtime/camera_speed.c b/runtime/camera_speed.c index 02bf1bd8..447c3c93 100644 --- a/runtime/camera_speed.c +++ b/runtime/camera_speed.c @@ -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; diff --git a/runtime/resolution.c b/runtime/resolution.c index 6f19623f..1e3584e5 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -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.