Terry J. Reedy added the comment:

The Wikipedia sentence "The WAV format is limited to files that are less than 4 
GB, because of its use of a 32-bit unsigned integer to record the file size 
header" is unambiguous and appears correct (see below). The rest of the 
Wikipedia sentence "(some programs limit the file size to 2 GB)" must be 
because some programs mistakenly read into signed instead of unsigned ints and 
fail to later adjust (by, for instance, later casting to unsigned).

The statement reflects the original specification given in reference 3, a .pdf. 
On page 11, it has
The basic building block of a RIFF file is called a chunk. Using C syntax, a 
chunk can be defined
as follows:
typedef unsigned long DWORD;
typedef DWORD CKSIZE; // 32-bit unsigned size value
typedef struct { // Chunk structure
  CKID ckID; // Chunk type identifier
  CKSIZE ckSize; // Chunk size field (size of ckData)
and on page 19
"<WORD> 16-bit unsigned quantity in Intel format    unsigned int"
INT and LONG are defined as 16 and 32 bit signed versions.

The WAVE specification, start on p. 56, uses WORD and DWORD, not INT and LONG 
for chunk header fields. Certainly, the 2 bytes for samples/sec should be 
unsigned to allow the standard 44100 CD rate.

(reference 4) summarized the .wav chunk formats. I think it just takes it for 
granted that sizes and counts are unsigned.

The patch given did not touch the write format in line 469(3.3.0):
The first 'l' is filled with 36 + self._datalength and I believe the whole 
thing should be '<L4s4sLHHLLHH4s'. The two struct.unpack formats on lines 264 
and 266 should also be changed.

A workaround is to write large numbers as signed negatives.
>>> struct.unpack('L', struct.pack('l', 3000000000 -2**32))
>>> struct.unpack('H', struct.pack('h', 44100 - 2**16))[0]

It is possible that someone is using this to write CD-quality files. It is also 
possible that anyone who has tried just gave up.

nosy: +terry.reedy

Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to