So I just noticed this, and after some experimentation, I managed to make it reproducible. I didn't see this posted anywhere. Python seems to be reading past the end of files in certain circumstances.
I'm using Python 2.7.12
f = open('test', 'wb')
f.write('this is a test')
f.close()
Right now, "test" is a 14 byte file with the text "this is a test".
f = open('test', 'rb+')
f.write('abcd')
x = f.read(1024*1024)
f.close()
Now "test" is a 4110 byte file, with this sort of content https://i.stack.imgur.com/xuBrn.png
Is this a bug? Is this a security risk?