I am using fread to read a large chunk of image data (> 1 MB) from a file. I recently encountered a bug on MinGW with Windows network shares where a single call to fread like
fread(file, 4, 100000, data);
fails reliably with an "Invalid argument" error, but 10 calls of
fread(file, 4, 10000, data); data += 10000;
succeed and yield the right result. I deduce there must be a maximum size for an fread, which I was not aware of before. I bisected the allowed size of fread and found it to be between 31000 and 32000 blocks of 4 bytes. Has anyone encountered this before? Is this a bug in MinGW? Is there any way to determine the maximum "safe" size for fread?
It's a known bug in MSVCRT (the Microsoft Visual C Runtime, which mingw uses) that fread
(and perhaps also the underlying _read
or whatever..?) fails on moderately long read lengths. You can either break the read down into smaller parts, write your own version of fread
to replace the system one (but only do this when compiling on broken systems!), or switch to a better runtime environment (like cygwin) that's not full of bugs...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With