New submission from Brian Mearns <bmea...@ieee.org>: Open a file in "w+b" mode: if you write to the file, then read from it without seeking backward, it reads past the EOF, apparently out into memory, which could be a pretty bad security concern. Have not checked if "w+" mode does the same.
### Bad behavior... >>> fid = open("temp", "w+b") >>> fid.read() '' >>> fid.write("foobar") #Read while positioned on EOF >>> fid.read(10) '\xc2\x00\x00\x00\x00\x00\x00\x00\x00\x00' >>> fid.seek(0) >>> fid.read(10) 'foobar\xc2\x00\x00\x00' >>> fid.close() ###Correct behavior after seeking backwards: >>> fid = open("temp2", "w+b") >>> fid.read() '' >>> fid.write("foobar") >>> fid.seek(0) >>> fid.read(10) 'foobar' >>> fid.close() Interestingly, it appears that any seek works, you don't necessarily have to go backwards: >>> fid = open("temp2", "w+b") >>> fid.write("foobar") >>> fid.tell() 6L >>> fid.seek(6) >>> fid.read() '' ---------- components: IO messages: 89941 nosy: bmearns severity: normal status: open title: File reads past EOF in "w+b" mode type: security versions: Python 2.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6390> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com