--- leptonlib-1.52/src/readfile.c 2007-11-25 01:15:24.000000000 +0300 +++ leptonlib-1.52.new/src/readfile.c 2007-12-20 13:44:19.000000000 +0300 @@ -276,7 +276,7 @@ findFileFormat(FILE *fp) { l_uint8 firstbytes[12]; -l_int32 format; +l_int32 format, ret; PROCNAME("findFileFormat"); @@ -287,7 +287,10 @@ if (nbytesInFile(fp) < 12) return ERROR_INT("truncated file", procName, 0); - fread((char *)&firstbytes, 1, 12, fp); + ret = fread((char *)&firstbytes, 1, 12, fp); + if (ret != 12) + return ERROR_INT("failed to read first 12 bytes of file", procName, 0); + rewind(fp); format = findFileFormatBuffer(firstbytes);