src/wav.c : Fix broadcast ext related bug.

This commit is contained in:
Erik de Castro Lopo 2008-10-26 23:44:46 +11:00
parent 463007d36b
commit df5cacc814

View File

@ -94,7 +94,7 @@
#define OggS_MARKER (MAKE_MARKER ('O', 'g', 'g', 'S'))
#define WAV_PEAK_CHUNK_SIZE(ch) (2 * sizeof (int) + ch * (sizeof (float) + sizeof (int)))
#define WAV_BEXT_CHUNK_SIZE 602
#define WAV_BEXT_MIN_CHUNK_SIZE 602 /* offsetof (SF_BROADCAST_INFO, coding_history_size) */
enum
{ HAVE_RIFF = 0x01,
@ -568,11 +568,6 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
parsestage |= HAVE_other ;
*/
psf_binheader_readf (psf, "4", &dword) ;
if (dword < WAV_BEXT_CHUNK_SIZE)
psf_log_printf (psf, "bext : %u (should be >= %d)\n", dword, WAV_BEXT_CHUNK_SIZE) ;
else
psf_log_printf (psf, "bext : %u\n", dword) ;
if ((error = wav_read_bext_chunk (psf, dword)))
return error ;
break ;
@ -1621,6 +1616,14 @@ wav_read_bext_chunk (SF_PRIVATE *psf, unsigned int chunksize)
SF_BROADCAST_INFO* b ;
unsigned int bytes = 0 ;
if (chunksize < WAV_BEXT_MIN_CHUNK_SIZE)
{ psf_log_printf (psf, "bext : %u (should be >= %d)\n", chunksize, WAV_BEXT_MIN_CHUNK_SIZE) ;
psf_binheader_readf (psf, "j", chunksize) ;
return 0 ;
} ;
psf_log_printf (psf, "bext : %u\n", chunksize) ;
if ((psf->broadcast_var = broadcast_var_alloc (chunksize + 128)) == NULL)
{ psf->error = SFE_MALLOC_FAILED ;
return psf->error ;
@ -1636,17 +1639,13 @@ wav_read_bext_chunk (SF_PRIVATE *psf, unsigned int chunksize)
bytes += psf_binheader_readf (psf, "442", &b->time_reference_low, &b->time_reference_high, &b->version) ;
bytes += psf_binheader_readf (psf, "bj", &b->umid, sizeof (b->umid), 190) ;
if (chunksize > WAV_BEXT_CHUNK_SIZE)
if (chunksize > WAV_BEXT_MIN_CHUNK_SIZE)
{ /* File has coding history data. */
b->coding_history_size = chunksize - WAV_BEXT_CHUNK_SIZE ;
if (b->coding_history_size > SIGNED_SIZEOF (b->coding_history))
b->coding_history_size = SIGNED_SIZEOF (b->coding_history) ;
b->coding_history_size = chunksize - WAV_BEXT_MIN_CHUNK_SIZE ;
/* We do not parse the coding history */
bytes += psf_binheader_readf (psf, "b", b->coding_history, b->coding_history_size) ;
b->coding_history [sizeof (b->coding_history) - 1] = 0 ;
} ;
if (bytes < chunksize)
@ -1664,7 +1663,7 @@ wav_write_bext_chunk (SF_PRIVATE *psf)
b = & psf->broadcast_var->binfo ;
psf_binheader_writef (psf, "m4", bext_MARKER, WAV_BEXT_CHUNK_SIZE + b->coding_history_size) ;
psf_binheader_writef (psf, "m4", bext_MARKER, WAV_BEXT_MIN_CHUNK_SIZE + b->coding_history_size) ;
/*
** Note that it is very important the the field widths of the SF_BROADCAST_INFO