New submission from Christian Kern:

Writing .wav files is limited to a file size of 2 Gib, while
the WAV file format itself supports up to 4 Gib.
Trying to write a file beyond 2 Gib (e.g. 203 minutes at
CD quality (i.e. 44.1 kHz, 2 channels, 16 bit)) will crash
at the moment when self._datawritten exceeds 2^31-1 bytes.
This is due to the fact that, in method "_patchheader",
the variable "self._datawritten" is written with
"struct.pack('<l')" (signed long integer)
instead of
"struct.pack('<L')" (unsigned long integer---which would
conform to the WAV file format spefication).

patch to wave.py:
476c476
<         self._file.write(struct.pack('<l', self._datalength))
---
>         self._file.write(struct.pack('<L', self._datalength))
485c485
<         self._file.write(struct.pack('<l', 36 + self._datawritten))
---
>         self._file.write(struct.pack('<L', 36 + self._datawritten))
487c487
<         self._file.write(struct.pack('<l', self._datawritten))
---
>         self._file.write(struct.pack('<L', self._datawritten))

This patch also patches the "_write_header" method, which
has the same problem (but will lead to a crash only
in very rare cases).

By the way: "_patchheader" should be renamed to "_patch_header"
in order to be in harmony with the other function/method names
of this module.

Attached you'll find a very simple python 2 script which will
reproduce the problem. Usage: mkdummywav.py $duration_in_minutes

Maybe the problem also occurs at python 3, I don't know.

----------
components: Extension Modules
files: mkdummywav.py
messages: 175450
nosy: ckern
priority: normal
severity: normal
status: open
title: wave module: wrong integer format
type: behavior
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file27971/mkdummywav.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16461>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to