Skip to content

Commit 018ebcb

Browse files
committed
check if there were transmitted more data than declared through filesize
1 parent 73ca7ab commit 018ebcb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

gathering.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,20 @@ int main(int argc, char **argv) {
102102

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

105-
if(bytes_read < file_size) {
105+
if(bytes_read != file_size) {
106106
free( buffer );
107107
fprintf(stderr, "image could not be loaded bytes_should:%i, bytes_read:%li\n", file_size, bytes_read);
108108
exit(EXIT_FAILURE);
109109
}
110110

111+
char buf2[1];
112+
if(fread(buf2, 1,1, stdin)>0) {
113+
fprintf(stderr, "after file_size (%i) is at least one byte further more to read\n", file_size);
114+
exit(EXIT_FAILURE);
115+
}
116+
117+
fclose(stdin);
118+
111119
gdImagePtr im;
112120
int ft = get_file_type_from_buf( buffer, file_size);
113121

0 commit comments

Comments
 (0)