summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-08-06 20:52:43 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-08-06 20:52:43 (GMT)
commit0473e56964ae9d041cfb0c3c8e09994cb58b675a (patch)
tree8e7ad0bb81f72d3200028ea50def9fe4a0871d89 /Modules/_io
parent825b993542563d76b08ca7b01729b20837ba9245 (diff)
downloadcpython-0473e56964ae9d041cfb0c3c8e09994cb58b675a.zip
cpython-0473e56964ae9d041cfb0c3c8e09994cb58b675a.tar.gz
cpython-0473e56964ae9d041cfb0c3c8e09994cb58b675a.tar.bz2
Merged revisions 74338 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r74338 | antoine.pitrou | 2009-08-06 22:29:56 +0200 (jeu., 06 août 2009) | 14 lines Merged revisions 74336 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74336 | antoine.pitrou | 2009-08-06 22:18:29 +0200 (jeu., 06 août 2009) | 8 lines Issue #6629: Fix a data corruption issue in the new `io` package, which could occur when writing to a BufferedRandom object (e.g. a file opened in "rb+" or "wb+" mode) after having buffered a certain amount of data for reading. This bug was not present in the pure Python implementation. Yes, this is a serious issue. ........ ................
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/bufferedio.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 98f8413..d8b6471 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -1757,6 +1757,19 @@ bufferedwriter_write(buffered *self, PyObject *args)
}
Py_CLEAR(res);
+ /* Adjust the raw stream position if it is away from the logical stream
+ position. This happens if the read buffer has been filled but not
+ modified (and therefore _bufferedwriter_flush_unlocked() didn't rewind
+ the raw stream by itself).
+ Fixes issue #6629.
+ */
+ n = RAW_OFFSET(self);
+ if (n != 0) {
+ if (_buffered_raw_seek(self, -n, 1) < 0)
+ goto error;
+ self->raw_pos -= n;
+ }
+
/* Then write buf itself. At this point the buffer has been emptied. */
remaining = buf.len;
written = 0;