F2G bug (was Re: How to calc easier the "long" filesize from nFileSizeLow and nFileSizeHigh)

John Machin sjmachin at lexicon.net
Wed May 31 00:55:03 CEST 2006


On 30/05/2006 1:55 PM, Roger Upole *top-posted*:

> Shift nFileSizeHigh by 32 and add FileSizeLow.

Uh-ohh. Here we have yet another manifestation of the Y2K bug's little 
sibling, the F2G bug.

The above doesn't work for 2GB <= filesize < 4GB, 6GB <= filesize < 8GB, 
etc. See below.

> 
>      Roger
> 
> "DurumDara" <durumdara at gmail.com> wrote in message news:mailman.6311.1148917245.27775.python-list at python.org...
>> Hi !
>>
>> I get the file datas with FindFilesW.
>> I want to calc the filesize from nFileSizeLow and nFileSizeHigh with easiest as possible, without again calling os.getsize().
>> How to I do it ? I need good result !
>>
>> Thanx for help:
>>  dd 
> 

Those two items are defined as int (that's *signed* int) -- so if the 
punter has a 3 GB file, nFileSizeHigh will be zero and nFileSizeLow will 
be -1073741824. *Minus* 1 GB? Hey, d00d, who stole my file-system?

Try this:

fsz = (hi << 32) + lo
if lo < 0:
     fsz += 0x100000000

This problem is described in the first article found by googling for 
"nFileSizeHigh", as I suggested to the OP. Here is some evidence:

C:\junk>dir gb3.txt
[snip]
31/05/2006  07:59 AM     3,221,225,472 gb3.txt
[snip]
C:\junk>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
|>>> import win32file
|>>> d = win32file.FindFilesW(u'gb3.txt')
|>>> d
[(32, <PyTime:30/05/2006 9:43:06 PM>, <PyTime:30/05/2006 9:59:06 PM>, 
<PyTime:30/05/2006 9:59:06 PM>, 0, -1073741824, 0, 0, u'gb3.txt', u'')]
|>>> hi, lo = d[0][4:6]
|>>> hi, lo
(0, -1073741824)
|>>> fsz = (hi << 32) + lo
|>>> fsz
-1073741824
|>>> # if lo < 0:
|... fsz += (1 << 32)
|>>>
|>>> fsz
3221225472L
|>>>

Cheers,
John




More information about the Python-list mailing list