Index: Lib/test/test_array.py =================================================================== --- Lib/test/test_array.py (revision 69994) +++ Lib/test/test_array.py (working copy) @@ -174,9 +174,8 @@ b.fromfile(f, len(self.example)) self.assertEqual(b, array.array(self.typecode, self.example)) self.assertNotEqual(a, b) - b.fromfile(f, len(self.example)) + self.assertRaises(EOFError, b.fromfile, f, len(self.example)+1) self.assertEqual(a, b) - self.assertRaises(EOFError, b.fromfile, f, 1) f.close() finally: if not f.closed: Index: Modules/arraymodule.c =================================================================== --- Modules/arraymodule.c (revision 69994) +++ Modules/arraymodule.c (working copy) @@ -1201,6 +1201,7 @@ PyObject *f, *b, *res; Py_ssize_t itemsize = self->ob_descr->itemsize; Py_ssize_t n, nbytes; + int not_enough_bytes; if (!PyArg_ParseTuple(args, "On:fromfile", &f, &n)) return NULL; @@ -1222,12 +1223,7 @@ return NULL; } - if (PyBytes_GET_SIZE(b) != nbytes) { - PyErr_SetString(PyExc_EOFError, - "read() didn't return enough bytes"); - Py_DECREF(b); - return NULL; - } + not_enough_bytes = (PyBytes_GET_SIZE(b) != nbytes); args = Py_BuildValue("(O)", b); Py_DECREF(b); @@ -1236,7 +1232,16 @@ res = array_fromstring(self, args); Py_DECREF(args); + if (res == NULL) + return NULL; + if (not_enough_bytes) { + PyErr_SetString(PyExc_EOFError, + "read() didn't return enough bytes"); + Py_DECREF(res); + return NULL; + } + return res; }