ref: 2d99be19af699828da7e63b49e553523c02780bf
parent: e02d1db8faca48ce7a21dbe406cb7a7aa8754116
author: Ulrich Klauer <ulrich@chirlu.de>
date: Mon Mar 19 22:59:26 EDT 2012
MAUD format write fixes The MAUD format wrote a wrong FORM chunk size and didn't pad the data chunk to an even number of bytes, as required by the IFF specification. The problems were reported by Carl Eric Codère. This resolves tracker item 3507927.
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
File formats:
o Fix pipe file-type detection regression. (robs)
+ o MAUD write fixes. [3507927] (Carl Eric Codere and Ulrich Klauer)
Other bug fixes:
--- a/src/maud.c
+++ b/src/maud.c
@@ -2,6 +2,8 @@
*
* supports: mono and stereo, linear, a-law and u-law reading and writing
*
+ * an IFF format; description at http://lclevy.free.fr/amiga/MAUDINFO.TXT
+ *
* Copyright 1998-2006 Chris Bagwell and SoX Contributors
* This source code is freely redistributable and may be used for
* any purpose. This copyright notice must be maintained.
@@ -227,6 +229,11 @@
{
/* All samples are already written out. */
+ priv_t *p = (priv_t*)ft->priv;
+ uint32_t mdat_size; /* MDAT chunk size */
+ mdat_size = p->nsamples * (ft->encoding.bits_per_sample >> 3);
+ lsx_padbytes(ft, (size_t) (mdat_size%2));
+
if (lsx_seeki(ft, (off_t)0, 0) != 0)
{
lsx_fail_errno(ft,errno,"can't rewind output file to rewrite MAUD header");
@@ -237,13 +244,16 @@
return(SOX_SUCCESS);
}
-#define MAUDHEADERSIZE (4+(4+4+32)+(4+4+32)+(4+4))
+#define MAUDHEADERSIZE (4+(4+4+32)+(4+4+19+1)+(4+4))
static void maudwriteheader(sox_format_t * ft)
{
priv_t * p = (priv_t *) ft->priv;
+ uint32_t mdat_size; /* MDAT chunk size */
+ mdat_size = p->nsamples * (ft->encoding.bits_per_sample >> 3);
+
lsx_writes(ft, "FORM");
- lsx_writedw(ft, (p->nsamples* (ft->encoding.bits_per_sample >> 3)) + MAUDHEADERSIZE); /* size of file */
+ lsx_writedw(ft, MAUDHEADERSIZE + mdat_size + mdat_size%2); /* size of file */
lsx_writes(ft, "MAUD"); /* File type */
lsx_writes(ft, "MHDR");
@@ -308,8 +318,9 @@
lsx_writedw(ft, 0); /* reserved */
lsx_writes(ft, "ANNO");
- lsx_writedw(ft, 30); /* length of block */
- lsx_writes(ft, "file create by Sound eXchange ");
+ lsx_writedw(ft, 19); /* length of block */
+ lsx_writes(ft, "file created by SoX");
+ lsx_padbytes(ft, (size_t)1);
lsx_writes(ft, "MDAT");
lsx_writedw(ft, p->nsamples * (ft->encoding.bits_per_sample >> 3)); /* samples in file */