mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-27 03:50:29 +00:00
Fix bugs where invalid files can cause a divide by zero exception (SIGFPE). Thanks to Sami Liedes for reporting this a Debian bug #530831.
This commit is contained in:
parent
313be08430
commit
cb3c87aa3b
@ -1,3 +1,9 @@
|
||||
2009-05-28 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/alaw.c src/float32.c src/htk.c src/pcm.c src/sds.c src/ulaw.c
|
||||
Fix bugs where invalid files can cause a divide by zero error (SIGFPE).
|
||||
Thanks to Sami Liedes for reporting this a Debian bug #530831.
|
||||
|
||||
2009-05-25 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* configure.ac src/sndfile.h.in
|
||||
|
@ -69,7 +69,7 @@ alaw_init (SF_PRIVATE *psf)
|
||||
else
|
||||
psf->datalength = 0 ;
|
||||
|
||||
psf->sf.frames = psf->datalength / psf->blockwidth ;
|
||||
psf->sf.frames = psf->blockwidth > 0 ? psf->datalength / psf->blockwidth : 1 ;
|
||||
|
||||
return 0 ;
|
||||
} /* alaw_init */
|
||||
|
@ -241,7 +241,7 @@ float32_init (SF_PRIVATE *psf)
|
||||
else
|
||||
psf->datalength = 0 ;
|
||||
|
||||
psf->sf.frames = psf->datalength / psf->blockwidth ;
|
||||
psf->sf.frames = psf->blockwidth > 0 ? psf->datalength / psf->blockwidth : 0 ;
|
||||
|
||||
return 0 ;
|
||||
} /* float32_init */
|
||||
|
13
src/htk.c
13
src/htk.c
@ -195,10 +195,17 @@ htk_read_header (SF_PRIVATE *psf)
|
||||
return SFE_HTK_NOT_WAVEFORM ;
|
||||
|
||||
psf->sf.channels = 1 ;
|
||||
psf->sf.samplerate = 10000000 / sample_period ;
|
||||
|
||||
psf_log_printf (psf, "HTK Waveform file\n Sample Count : %d\n Sample Period : %d => %d Hz\n",
|
||||
sample_count, sample_period, psf->sf.samplerate) ;
|
||||
if (sample_period > 0)
|
||||
{ psf->sf.samplerate = 10000000 / sample_period ;
|
||||
psf_log_printf (psf, "HTK Waveform file\n Sample Count : %d\n Sample Period : %d => %d Hz\n",
|
||||
sample_count, sample_period, psf->sf.samplerate) ;
|
||||
}
|
||||
else
|
||||
{ psf->sf.samplerate = 16000 ;
|
||||
psf_log_printf (psf, "HTK Waveform file\n Sample Count : %d\n Sample Period : %d (should be > 0) => Guessed sample rate %d Hz\n",
|
||||
sample_count, sample_period, psf->sf.samplerate) ;
|
||||
} ;
|
||||
|
||||
psf->sf.format = SF_FORMAT_HTK | SF_FORMAT_PCM_16 ;
|
||||
psf->bytewidth = 2 ;
|
||||
|
@ -271,7 +271,7 @@ pcm_init (SF_PRIVATE *psf)
|
||||
else
|
||||
psf->datalength = 0 ;
|
||||
|
||||
psf->sf.frames = psf->datalength / psf->blockwidth ;
|
||||
psf->sf.frames = psf->blockwidth > 0 ? psf->datalength / psf->blockwidth : 1 ;
|
||||
|
||||
return 0 ;
|
||||
} /* pcm_init */
|
||||
|
35
src/sds.c
35
src/sds.c
@ -219,21 +219,40 @@ sds_read_header (SF_PRIVATE *psf, SDS_PRIVATE *psds)
|
||||
if (marker != 0xF07E || byte != 0x01)
|
||||
return SFE_SDS_NOT_SDS ;
|
||||
|
||||
psf_log_printf (psf, "Midi Sample Dump Standard (.sds)\nF07E\n Midi Channel : %d\n", channel) ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "e213", &sample_no, &bitwidth, &samp_period) ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "e2", &sample_no) ;
|
||||
sample_no = SDS_3BYTE_TO_INT_DECODE (sample_no) ;
|
||||
|
||||
psf_log_printf (psf, "Midi Sample Dump Standard (.sds)\nF07E\n"
|
||||
" Midi Channel : %d\n Sample Number : %d\n",
|
||||
channel, sample_no) ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "e13", &bitwidth, &samp_period) ;
|
||||
|
||||
samp_period = SDS_3BYTE_TO_INT_DECODE (samp_period) ;
|
||||
|
||||
psds->bitwidth = bitwidth ;
|
||||
|
||||
psf->sf.samplerate = 1000000000 / samp_period ;
|
||||
if (psds->bitwidth > 1)
|
||||
psf_log_printf (psf, " Bit Width : %d\n", psds->bitwidth) ;
|
||||
else
|
||||
{ psf_log_printf (psf, " Bit Width : %d (should be > 1)\n", psds->bitwidth) ;
|
||||
return SFE_SDS_BAD_BIT_WIDTH ;
|
||||
} ;
|
||||
|
||||
psf_log_printf (psf, " Sample Number : %d\n"
|
||||
" Bit Width : %d\n"
|
||||
if (samp_period > 0)
|
||||
{ psf->sf.samplerate = 1000000000 / samp_period ;
|
||||
|
||||
psf_log_printf (psf, " Sample Period : %d\n"
|
||||
" Sample Rate : %d\n",
|
||||
sample_no, psds->bitwidth, psf->sf.samplerate) ;
|
||||
samp_period, psf->sf.samplerate) ;
|
||||
}
|
||||
else
|
||||
{ psf->sf.samplerate = 16000 ;
|
||||
|
||||
psf_log_printf (psf, " Sample Period : %d (should be > 0)\n"
|
||||
" Sample Rate : %d (guessed)\n",
|
||||
samp_period, psf->sf.samplerate) ;
|
||||
} ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "e3331", &data_length, &sustain_loop_start, &sustain_loop_end, &loop_type) ;
|
||||
|
||||
|
@ -59,7 +59,7 @@ ulaw_init (SF_PRIVATE *psf)
|
||||
else
|
||||
psf->datalength = 0 ;
|
||||
|
||||
psf->sf.frames = psf->datalength / psf->blockwidth ;
|
||||
psf->sf.frames = psf->blockwidth > 0 ? psf->datalength / psf->blockwidth : 1 ;
|
||||
|
||||
return 0 ;
|
||||
} /* ulaw_init */
|
||||
|
Loading…
Reference in New Issue
Block a user