Offset sanity checks

This commit is contained in:
surkeh
2018-04-19 05:58:35 -07:00
parent 2977274f93
commit 889a3e44a6
6 changed files with 15 additions and 7 deletions
+5 -1
View File
@@ -100,7 +100,8 @@ static bool getmeshbatch(struct Batch *b,
// assume client has allocated memory for mesh
static bool getmesh(struct Mesh *m,
unsigned int i,
const char * const filedata) {
const char * const filedata,
unsigned int filesize) {
bool done = false;
if (m == NULL || filedata == NULL || m -> b == NULL) {
return done;
@@ -112,6 +113,9 @@ static bool getmesh(struct Mesh *m,
struct Batch b;
for (j = 0; j < mh -> numBatch; j++) {
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
if (offset > filesize) {
return done;
}
getmeshbatch(&b, offset, filedata);
// printmeshbatch(&b);
m -> b[j] = b;
+3 -1
View File
@@ -8,7 +8,9 @@ static bool getpldh(struct PldHeader *ph, const char *filedata) {
if (ph != NULL && filedata != NULL) {
ph -> numOffset = (int32_t)filedata[0];
ph -> offsets = (uint32_t*)(filedata + sizeof(int32_t));
good = true;
if ( ph->numOffset > 0 ) {
good = true;
}
}
return good;
}
+1 -1
View File
@@ -37,7 +37,7 @@ static bool gettexdescriptor(struct TextureBatchDescriptor **descriptor,
bool done = false;
unsigned int offset = sizeof(struct TexturePack);
offset += sizeof(struct TextureBatchDescriptor) * i;
if (filedata != NULL) {
if (filedata != NULL && offset <= filesize) {
*descriptor = (struct TextureBatchDescriptor*)(filedata + offset);
done = true;
}