Message145477
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 |
|
Date |
User |
Action |
Args |
2011-10-13 18:40:10 | Alexander.Steppke | set | recipients:
+ Alexander.Steppke |
2011-10-13 18:40:10 | Alexander.Steppke | set | messageid: <1318531210.93.0.392401137226.issue13171@psf.upfronthosting.co.za> |
2011-10-13 18:40:10 | Alexander.Steppke | link | issue13171 messages |
2011-10-13 18:40:10 | Alexander.Steppke | create | |
|