Fix potential buffer overrun

This commit rearranges record size comparison and fread() to make sure
fread() only reads the data that can fit into the buffer.
1 file changed