This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Alexander.Steppke
Recipients Alexander.Steppke
Date 2011-10-13.18:40:10
SpamBayes Score 4.9845683e-11
Marked as misclassified No
Message-id <1318531210.93.0.392401137226.issue13171@psf.upfronthosting.co.za>
In-reply-to
Content
The tempfile module shows strange behavior under certain conditions. This might lead to data leaking or other problems. 

The test session looks as follows:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tmp = tempfile.TemporaryFile()
>>> tmp.read()
''
>>> tmp.write('test')
>>> tmp.read()
'P\xf6D\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ [ommitted]'

or similar behavior in text mode: 

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tmp = tempfile.TemporaryFile('w+t')
>>> tmp.read()
''
>>> tmp.write('test')
>>> tmp.read()
'\x00\xa5\x8b\x02int or long, hash(a) is used instead.\n    i\x10 [ommitted]'
>>> tmp.seek(0)
>>> tmp.readline()
'test\x00\xa5\x8b\x02int or long, hash(a) is used instead.\n'

This bug seems to be triggered by calling tmp.read() before tmp.seek(). I am running Python 2.7.2 on Windows 7 x64, other people have reproduced the problem on Windows XP but not under Linux or Cygwin (see also http://stackoverflow.com/questions/7757663/python-tempfile-broken-or-am-i-doing-it-wrong).

Thank you for looking into this.
Alexander
History
Date User Action Args
2011-10-13 18:40:10Alexander.Steppkesetrecipients: + Alexander.Steppke
2011-10-13 18:40:10Alexander.Steppkesetmessageid: <1318531210.93.0.392401137226.issue13171@psf.upfronthosting.co.za>
2011-10-13 18:40:10Alexander.Steppkelinkissue13171 messages
2011-10-13 18:40:10Alexander.Steppkecreate