You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After a fair bit of debugging we've tracked down a bug in OSX's fwrite() (actually in an internal function that affects fwrite(), fprintf(), and other functions that write to a file handle). This bug was originally discovered by trying to write out some large arrays with Numpy. As far as I can tell (from some Google searches) this bug isn't otherwise well known yet.
The bug is that at some point the size passed to fwrite() is stuffed into a 32-bit register and checks if it's a multiple of 0x1000 (4096) and then branches off to some separate routine for doing writes that are a multiple of one block size.
Thus, if the size is a multiple of 4096 and >= 2**32, the size gets silently truncated to size & 0xffffffff.
The attached test program illustrates the problem. This has been tested and been shown buggy on Leopard and Lion (and so presumably the bug exists in Snow Leopard--not sure about earlier OSX versions).
Further testing has shown that this holds for any multiple of 4096.
The fix that was implemented for #2256, where arrays are written in 2GB chunks, would also solve this problem. So I think it would probably be sufficient to just enable the same chunked write code block in PyArray_ToFile() on OSX as well.
Although the OSX bug only occurs on those 4K boundaries and only for sizes >= 2**32, for the sake of simplicity I think it's fine to just use more or less the same workaround.
The text was updated successfully, but these errors were encountered:
I h8 these buggy OS workarounds. But we are here to serve ;) If you can put together a pull request with a fix and test using #2256 as a template I'll put it in. And thanks for tracking it down.
Original ticket http://projects.scipy.org/numpy/ticket/2114 on 2012-04-24 by trac user embray, assigned to unknown.
After a fair bit of debugging we've tracked down a bug in OSX's fwrite() (actually in an internal function that affects fwrite(), fprintf(), and other functions that write to a file handle). This bug was originally discovered by trying to write out some large arrays with Numpy. As far as I can tell (from some Google searches) this bug isn't otherwise well known yet.
The bug is that at some point the size passed to fwrite() is stuffed into a 32-bit register and checks if it's a multiple of 0x1000 (4096) and then branches off to some separate routine for doing writes that are a multiple of one block size.
Thus, if the size is a multiple of 4096 and >= 2**32, the size gets silently truncated to
size & 0xffffffff
.The attached test program illustrates the problem. This has been tested and been shown buggy on Leopard and Lion (and so presumably the bug exists in Snow Leopard--not sure about earlier OSX versions).
This is what the output looks like:
As you can see, fwrite() even returns that it wrote "4294967296 bytes", though in reality it wrote zero bytes. Likewise:
Further testing has shown that this holds for any multiple of 4096.
The fix that was implemented for #2256, where arrays are written in 2GB chunks, would also solve this problem. So I think it would probably be sufficient to just enable the same chunked write code block in
PyArray_ToFile()
on OSX as well.Although the OSX bug only occurs on those 4K boundaries and only for sizes >= 2**32, for the sake of simplicity I think it's fine to just use more or less the same workaround.
The text was updated successfully, but these errors were encountered: