Message135830
| Author |
genstein |
| Recipients |
genstein |
| Date |
2011年05月12日.13:07:27 |
| SpamBayes Score |
7.392065e-09 |
| Marked as misclassified |
No |
| Message-id |
<1305205648.13.0.328834738921.issue12062@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Reporting this as requested by Antoine Pitrou: Under certain circumstances in Python 3.2 (r32:88445) it's possible for buffered I/O to lose data before it is written and/or return the wrong results when reading. I tripped over this issue whilst writing an assembler which first writes out a bunch of binary data and then goes back over it in a somewhat arbitrary order patching addresses.
The following code demonstrates the issue:
[code]
START = 0
MID = 1
LENGTH = 4
def test(buffering):
f = open("test.bin", "w+b", buffering = buffering)
for i in range(LENGTH):
f.write(b'\x00')
f.seek(MID)
f.read(1)
f.write(b'\x00')
f.seek(MID)
f.write(b'\x01')
f.seek(START)
f.seek(MID)
print(f.read(1))
f.close()
print("Buffered result: ")
test(-1)
print("Unbuffered result:")
test(0)
[end code]
Output on both Gentoo and Vista is:
Buffered result:
b'\x00'
Unbuffered result:
b'\x01'
Expected output is b'\x01' in both cases.
The issue is reproducible with larger files provided that the constants are increased ~proportionally (START 0, MID 500, LENGTH 1000 for example). Transposing the buffered/unbuffered tests and/or using different buffer sizes for the buffered test seem have no effect.
The lengthy code at this URL also demonstrates the issue: http://pastebin.com/xqrzKr5D The above was produced from this code, which was autogenerated by intercepting my assembler's output. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2011年05月12日 13:07:28 | genstein | set | recipients:
+ genstein |
| 2011年05月12日 13:07:28 | genstein | set | messageid: <1305205648.13.0.328834738921.issue12062@psf.upfronthosting.co.za> |
| 2011年05月12日 13:07:27 | genstein | link | issue12062 messages |
| 2011年05月12日 13:07:27 | genstein | create |
|