Skip to content

Commit

Permalink
check if there were transmitted more data than declared through filesize
Browse files Browse the repository at this point in the history
  • Loading branch information
f7a8 committed Dec 7, 2021
1 parent 73ca7ab commit 018ebcb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gathering.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ int main(int argc, char **argv) {

size_t bytes_read = fread(buffer, 1, file_size, stdin);

if(bytes_read < file_size) {
if(bytes_read != file_size) {
free( buffer );
fprintf(stderr, "image could not be loaded bytes_should:%i, bytes_read:%li\n", file_size, bytes_read);
exit(EXIT_FAILURE);
}

char buf2[1];
if(fread(buf2, 1,1, stdin)>0) {
fprintf(stderr, "after file_size (%i) is at least one byte further more to read\n", file_size);
exit(EXIT_FAILURE);
}

fclose(stdin);

gdImagePtr im;
int ft = get_file_type_from_buf( buffer, file_size);

Expand Down

0 comments on commit 018ebcb

Please sign in to comment.