[NumPy-Tickets] [NumPy] #1388: numpy.frombuffer calls PyErr_Format without actually throwing the error, causing bizarre errors later (was: Bizarre errors after numpy.frombuffer with zero-length buffer)
NumPy Trac
numpy-tickets@scipy....
Mon Feb 8 08:58:17 CST 2010
#1388: numpy.frombuffer calls PyErr_Format without actually throwing the error,
causing bizarre errors later
------------------------+---------------------------------------------------
Reporter: baffe | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: numpy.core | Version: 1.4.0
Keywords: |
------------------------+---------------------------------------------------
Changes (by baffe):
* component: Other => numpy.core
Comment:
Anybody home?
Some more investigation:
ctors.c:3103, in !PyArray_FromBuffer
{{{
if ((offset < 0) || (offset >= ts)) {
PyErr_Format(PyExc_ValueError,
"offset must be positive and smaller than %"
INTP_FMT, (intp)ts);
}
}}}
ts is zero for a zero-size buffer. Note lack of return NULL here.
descriptor.c:1266, in !PyArray_DescrConverter:
{{{
if (PyErr_Occurred()) {
goto fail;
}
}}}
This does not check that the error was caused by anything this function
did, and always throws the "data type not understood" error, in this case
ignoring the previously existing error.
I assume the first of these blocks is wrong. I suggest both returning NULL
and changing the condition to (offset < 0) || (offset > ts) to allow zero-
size buffers. I haven't checked if allowing zero-size buffers will cause
other problems.
(Just noticed the "![1]" in the original example is a cut-and-paste error,
it should of course be "![42]".)
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1388#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list