diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-03-13 23:42:55 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-03-13 23:42:55 (GMT) |
commit | a28fcfdbdaa082a8d3849d7dc829f89cd7f868a8 (patch) | |
tree | 8f442d68459df06ab7d77f9db01365b2e2ae56e0 /Modules | |
parent | 0ae29cf6176d3f80c1845cf23716a708acbe598b (diff) | |
download | cpython-a28fcfdbdaa082a8d3849d7dc829f89cd7f868a8.zip cpython-a28fcfdbdaa082a8d3849d7dc829f89cd7f868a8.tar.gz cpython-a28fcfdbdaa082a8d3849d7dc829f89cd7f868a8.tar.bz2 |
Issue #5016: FileIO.seekable() could return False if the file position
was negative when truncated to a C int. Patch by Victor Stinner.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_fileio.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c index 32f6790..88ee54c 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -66,6 +66,8 @@ _PyFileIO_closed(PyObject *self) static PyObject * portable_lseek(int fd, PyObject *posobj, int whence); +static PyObject *portable_lseek(int fd, PyObject *posobj, int whence); + /* Returns 0 on success, -1 with exception set on failure. */ static int internal_close(PyFileIOObject *self) @@ -441,14 +443,14 @@ fileio_seekable(PyFileIOObject *self) if (self->fd < 0) return err_closed(); if (self->seekable < 0) { - int ret; - Py_BEGIN_ALLOW_THREADS - ret = lseek(self->fd, 0, SEEK_CUR); - Py_END_ALLOW_THREADS - if (ret < 0) + PyObject *pos = portable_lseek(self->fd, NULL, SEEK_CUR); + if (pos == NULL) { + PyErr_Clear(); self->seekable = 0; - else + } else { + Py_DECREF(pos); self->seekable = 1; + } } return PyBool_FromLong((long) self->seekable); } |