Ensure we don't read past end of file

This commit is contained in:
James Bowes 2012-09-06 12:08:06 -03:00
parent 3262f44afb
commit 3d94813dc8

View file

@ -154,6 +154,7 @@ load_content_sets(FILE *stream, struct node **list, int *node_count,
}
read = fread (buf, sizeof (char), CHUNK, stream);
unsigned char *eob = buf + read;
if (stats) {
printf("\tbytes: %zu\n", read);
}
@ -191,6 +192,10 @@ load_content_sets(FILE *stream, struct node **list, int *node_count,
raw);
buf = buf + bits_read / 8;
bits_read = bits_read % 8;
if (buf >= eob) {
printf ("\nread too much: dictionary lookup\n");
return -1;
}
if (path[0] == '\0') {
if (raw) {
@ -213,6 +218,10 @@ load_content_sets(FILE *stream, struct node **list, int *node_count,
buf = buf + bits_read / 8;
bits_read = bits_read % 8;
if (buf >= eob) {
printf ("\nread too much: path lookup\n");
return -1;
}
node->paths[node->count] = path;
node->children[node->count] = child;