Ensure we don't read past end of file
This commit is contained in:
parent
3262f44afb
commit
3d94813dc8
1 changed files with 9 additions and 0 deletions
9
unpack.c
9
unpack.c
|
@ -154,6 +154,7 @@ load_content_sets(FILE *stream, struct node **list, int *node_count,
|
||||||
}
|
}
|
||||||
|
|
||||||
read = fread (buf, sizeof (char), CHUNK, stream);
|
read = fread (buf, sizeof (char), CHUNK, stream);
|
||||||
|
unsigned char *eob = buf + read;
|
||||||
if (stats) {
|
if (stats) {
|
||||||
printf("\tbytes: %zu\n", read);
|
printf("\tbytes: %zu\n", read);
|
||||||
}
|
}
|
||||||
|
@ -191,6 +192,10 @@ load_content_sets(FILE *stream, struct node **list, int *node_count,
|
||||||
raw);
|
raw);
|
||||||
buf = buf + bits_read / 8;
|
buf = buf + bits_read / 8;
|
||||||
bits_read = 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 (path[0] == '\0') {
|
||||||
if (raw) {
|
if (raw) {
|
||||||
|
@ -213,6 +218,10 @@ load_content_sets(FILE *stream, struct node **list, int *node_count,
|
||||||
|
|
||||||
buf = buf + bits_read / 8;
|
buf = buf + bits_read / 8;
|
||||||
bits_read = 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->paths[node->count] = path;
|
||||||
node->children[node->count] = child;
|
node->children[node->count] = child;
|
||||||
|
|
Loading…
Reference in a new issue