[issue5395] array.fromfile not checking I/O errors

2009-10-05 Thread Eduardo Aguiar

Eduardo Aguiar  added the comment:

Maybe you could create a file without read permission (000) and try
to read from it.

--

___
Python tracker 
<http://bugs.python.org/issue5395>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5395] array.fromfile not checking I/O errors

2009-10-06 Thread Eduardo Aguiar

Eduardo Aguiar  added the comment:

Another try. I have opened a file for writing, and have tried to read
from it:

>>> fp = open ('xxx', 'w')
>>> fp.read ()
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 9] Bad file descriptor

--

___
Python tracker 
<http://bugs.python.org/issue5395>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5395] array.fromfile not checking I/O errors

2009-02-28 Thread Eduardo Aguiar

New submission from Eduardo Aguiar :

At arraymodule.c (line 1258):

nread = fread(item + (Py_SIZE(self) - n) * itemsize,
  itemsize, n, fp);
if (nread < (size_t)n) {
  Py_SIZE(self) -= (n - nread);
PyMem_RESIZE(item, char, Py_SIZE(self)*itemsize);
self->ob_item = item;
self->allocated = Py_SIZE(self);
PyErr_SetString(PyExc_EOFError,
 "not enough items in file");
return NULL;
}

When fread returns 0, ferror should be called to check if it was an EOF
or an error condition. It is not handling OSErrors, such as I/O errors,
raising always "not enough items in file".

--
components: Library (Lib)
messages: 82936
nosy: aguiar
severity: normal
status: open
title: array.fromfile not checking I/O errors
type: behavior
versions: Python 2.6

___
Python tracker 
<http://bugs.python.org/issue5395>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5396] os.read not handling O_DIRECT flag

2009-02-28 Thread Eduardo Aguiar

New submission from Eduardo Aguiar :

At posixmodule.c (line 6306)

static PyObject *
posix_read(PyObject *self, PyObject *args)
{
int fd, size, n;
PyObject *buffer;
if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))
return NULL;
if (size < 0) {
errno = EINVAL;
return posix_error();
}
buffer = PyString_FromStringAndSize((char *)NULL, size);
if (buffer == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
n = read(fd, PyString_AsString(buffer), size);
Py_END_ALLOW_THREADS
if (n < 0) {
Py_DECREF(buffer);
return posix_error();
}
if (n != size)
_PyString_Resize(&buffer, n);
return buffer;
}

os.read does not work with O_DIRECT flag. It fails with errno = EINVAL.

>From read(2) man page:

   EINVAL fd  is attached to an object which is unsuitable for
reading; or
  the file was opened with  the  O_DIRECT  flag,  and 
either  the
  address  specified  in buf, the value specified in count,
or the
  current file offset is not suitably aligned.

if os.open is called with O_DIRECT flag enabled, the buffer used in
"read" must be page aligned and "size" must be multiple of pagesize also.

--
components: Library (Lib)
messages: 82938
nosy: aguiar
severity: normal
status: open
title: os.read not handling O_DIRECT flag
type: behavior
versions: Python 2.6

___
Python tracker 
<http://bugs.python.org/issue5396>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5396] os.read not handling O_DIRECT flag

2009-03-15 Thread Eduardo Aguiar

Eduardo Aguiar  added the comment:

Hi,

I think I have a few more issues you can consider:

1) to allocated an aligned buffer it is as simple as allocate 4096 + len
(buffer) and truncate address to 4k boundary.

2) I wrote a floppy imager, and without O_DIRECT, it gives me 8 sectors
(4k = kernel page) errors whenever one sector is bad.

3) There is os.O_DIRECT and os.open help page references it

Best regards,
Eduardo Aguiar

--

___
Python tracker 
<http://bugs.python.org/issue5396>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com