[New-bugs-announce] [issue29817] File IO read, write, read causes garbage data write.

Jan report at bugs.python.org
Wed Mar 15 05:47:30 EDT 2017


New submission from Jan:

In Python 2.7.12 when reading, writing and subsequently reading again from a file, python seems to write garbage.

For example when running this in python IDLE: 

import os 
testPath = r"myTestFile.txt"

## Make sure the file exists and its empty
with open(testPath,"w") as tFile:
    tFile.write("")

print "Our Test File: ", os.path.abspath(testPath )

with open(testPath, "r+") as tFile:
    ## First we read the file 
    data = tFile.read()

    ## Now we write some data 
    tFile.write('Some Data')

    ## Now we read the file again
    tFile.read()


When now looking at the file the data is the following:

Some Data @ sb d Z d d l m Z d d d ・ ・ YZ e d k r^ d d l m Z e d d d d e ・n d S( s9
Implement Idle Shell history mechanism with History
...<omitted the rest of the data> 

As mentioned in the comments on stack overflow ( see link ) this might be a buffer overrun but I am not sure. Also I guess this could be used as a security vulnerability... 

http://stackoverflow.com/questions/40373457/python-r-read-write-read-writes-garbage-to-a-file?noredirect=1#comment72580538_40373457

----------
components: IO, Interpreter Core, Windows
messages: 289657
nosy: jan, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: File IO read, write, read causes garbage data write.
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29817>
_______________________________________


More information about the New-bugs-announce mailing list