From 4255947fe4d1800a143c3b28ee98beef521d38ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sun, 17 Apr 2016 14:15:06 +0200 Subject: [PATCH] fix crash when reading empty resource maps --- libres_internal.h | 4 ++-- res.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libres_internal.h b/libres_internal.h index 57bd540..6308685 100644 --- a/libres_internal.h +++ b/libres_internal.h @@ -68,13 +68,13 @@ struct __attribute__ ((__packed__)) RfMap { struct __attribute__ ((__packed__)) RfTypeEntry { // resource type entry uint32_t type; // resource type - uint16_t count; // number of resources minus one + int16_t count; // number of resources minus one uint16_t offset; // offset to ref list from type list }; struct __attribute__ ((__packed__)) RfTypeList { // resource type list - uint16_t count; // minus one + int16_t count; // minus one struct RfTypeEntry entry[]; }; diff --git a/res.c b/res.c index 6ca5bdf..e347bd1 100644 --- a/res.c +++ b/res.c @@ -280,7 +280,7 @@ RFILE* res_load (RFILE *rp) { uint8_t *names = ((void*)map)+ntohs(map->nameListOffset); // read types - rp->numTypes = 1+ntohs(types->count); + rp->numTypes = 1+(int16_t)ntohs(types->count); rp->types = calloc(rp->numTypes, sizeof(struct RmType)); if (rp->types == NULL) egoto(ENOMEM, error); bzero(rp->types, sizeof(struct RmType) * rp->numTypes);