src/(wav|w64).c : Handle error return values from psf_ftell.

This commit is contained in:
Erik de Castro Lopo 2009-02-22 17:20:34 +11:00
parent f3d0a6e5ce
commit 243ebd84f5
3 changed files with 28 additions and 24 deletions

View File

@ -34,12 +34,14 @@
* src/wav.c src/rf64.c
Ifdef out dead code that will be resurected some time in the future.
* src/xi.c
* src/wav.c src/w64.c src/xi.c
Handle error return values from psf_ftell.
* src/wav_w64.c
Fix handling and error checking of MSADPCM coefficient arrays.
2009-02-21 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/sd2.c

View File

@ -377,7 +377,7 @@ w64_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
break ;
} ; /* while (1) */
if (! psf->dataoffset)
if (psf->dataoffset <= 0)
return SFE_W64_NO_DATA ;
psf->endian = SF_ENDIAN_LITTLE ; /* All W64 files are little endian. */

View File

@ -400,28 +400,30 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
psf->datalength = dword ;
psf->dataoffset = psf_ftell (psf) ;
if (dword == 0 && RIFFsize == 8 && psf->filelength > 44)
{ psf_log_printf (psf, "*** Looks like a WAV file which wasn't closed properly. Fixing it.\n") ;
psf->datalength = psf->filelength - psf->dataoffset ;
if (psf->dataoffset > 0)
{ if (dword == 0 && RIFFsize == 8 && psf->filelength > 44)
{ psf_log_printf (psf, "*** Looks like a WAV file which wasn't closed properly. Fixing it.\n") ;
psf->datalength = psf->filelength - psf->dataoffset ;
} ;
if (psf->datalength > psf->filelength - psf->dataoffset)
{ psf_log_printf (psf, "data : %D (should be %D)\n", psf->datalength, psf->filelength - psf->dataoffset) ;
psf->datalength = psf->filelength - psf->dataoffset ;
}
else
psf_log_printf (psf, "data : %D\n", psf->datalength) ;
/* Only set dataend if there really is data at the end. */
if (psf->datalength + psf->dataoffset < psf->filelength)
psf->dataend = psf->datalength + psf->dataoffset ;
if (format == WAVE_FORMAT_MS_ADPCM && psf->datalength % 2)
{ psf->datalength ++ ;
psf_log_printf (psf, "*** Data length odd. Increasing it by 1.\n") ;
} ;
} ;
if (psf->datalength > psf->filelength - psf->dataoffset)
{ psf_log_printf (psf, "data : %D (should be %D)\n", psf->datalength, psf->filelength - psf->dataoffset) ;
psf->datalength = psf->filelength - psf->dataoffset ;
}
else
psf_log_printf (psf, "data : %D\n", psf->datalength) ;
/* Only set dataend if there really is data at the end. */
if (psf->datalength + psf->dataoffset < psf->filelength)
psf->dataend = psf->datalength + psf->dataoffset ;
if (format == WAVE_FORMAT_MS_ADPCM && psf->datalength % 2)
{ psf->datalength ++ ;
psf_log_printf (psf, "*** Data length odd. Increasing it by 1.\n") ;
} ;
if (! psf->sf.seekable)
if (! psf->sf.seekable || psf->dataoffset < 0)
break ;
/* Seek past data and continue reading header. */
@ -630,7 +632,7 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
} ;
} ; /* while (1) */
if (! psf->dataoffset)
if (psf->dataoffset <= 0)
return SFE_WAV_NO_DATA ;
/* WAVs can be little or big endian */
@ -1358,7 +1360,7 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk)
cptr = psf->u.cbuf ;
psf_binheader_readf (psf, "b", cptr, dword) ;
bytesread += dword ;
if (dword > SIGNED_SIZEOF (psf->u.cbuf))
if (dword >= SIGNED_SIZEOF (psf->u.cbuf))
cptr [sizeof (psf->u.cbuf) - 1] = 0 ;
else
cptr [dword > 0 ? dword : 0] = 0 ;