Large file support: truncate bug?

Paul Winkler bass at slinkp.com
Tue Oct 15 19:24:37 CEST 2002


Python 2.1.3, compiled from source on RedHat Linux 7.1 (kernel 2.4.something).
I *thought* I had large file support working:

>>> a = "a" * 1024 * 1024
>>> f = open('testbigfile', 'w')
>>> for i in range(3 * 1024): f.write(a)
>>> ...
>>> import os
>>> os.system('du -h testbigfile')
3.1G    testbigfile
0
>>> f.close()
>>> f = open('testbigfile', 'r')
>>>

Looks good, right? I can read and write a 3 GB file.
But...

>>> f.truncate(2L ** 31)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: long int too large to convert
>>> f.truncate(2L ** 31 - 1)
>>> os.system('du -h testbigfile')
2.1G    testbigfile
0


So the largest size you can truncate to is 2 ** 31 - 1 bytes.
Looks like a bug to me. ANyone else seen this?
I'm going to check the sourceforge tracker, and file a bug report
if I don't see one about this.

--PW



More information about the Python-list mailing list