Skip to content

Commit

Permalink
Fixed recursive function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
hoene committed Nov 24, 2019
1 parent e5367ca commit 2e6fac6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/hdf/fractalhead.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,
UNUSED(block_size);
UNUSED(block_offset);

if(reader->recursive_counter >= 10)
return MYSOFA_INVALID_FORMAT;
else
reader->recursive_counter++;

/* read signature */
if (fread(buf, 1, 4, reader->fhd) != 4 || strncmp(buf, "FHDB", 4)) {
log("cannot read signature of fractal heap indirect block\n");
return MYSOFA_INVALID_FORMAT;
}
log("%08" PRIX64 " %.4s\n", (uint64_t )ftell(reader->fhd) - 4, buf);
log("%08" PRIX64 " %.4s stack %d\n", (uint64_t )ftell(reader->fhd) - 4, buf, reader->recursive_counter);

if (fgetc(reader->fhd) != 0) {
log("object FHDB must have version 0\n");
Expand Down Expand Up @@ -218,6 +223,7 @@ static int directblockRead(struct READER *reader, struct DATAOBJECT *dataobject,

} while (typeandversion != 0);

reader->recursive_counter--;
return MYSOFA_OK;
}

Expand Down
2 changes: 2 additions & 0 deletions src/hdf/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ struct READER {
struct SUPERBLOCK superblock;

struct GCOL *gcol;

int recursive_counter;
};

int validAddress(struct READER *reader, uint64_t address);
Expand Down
1 change: 1 addition & 0 deletions src/hrtf/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ MYSOFA_EXPORT struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err) {
}
reader.gcol = NULL;
reader.all = NULL;
reader.recursive_counter = 0;

*err = superblockRead(&reader, &reader.superblock);

Expand Down

0 comments on commit 2e6fac6

Please sign in to comment.