Fix encoder crash with non-positive sample rates.
authorRalph Giles <giles@xiph.org>
Mon, 5 Jan 2015 18:04:20 +0000 (18:04 +0000)
committerRalph Giles <giles@xiph.org>
Mon, 5 Jan 2015 18:04:20 +0000 (18:04 +0000)
Input files with sampling rate 0 are useless and can make
libvorbis access invalid memory because the logic in
_vp_psy_init (and probably other functions) isn't prepared for
it. A sanity check lets the library refuse those inputs
gracefully in the initialization functions before they can
do harm.

Patch by Martin Steghöfer <martin@steghoefer.eu>

Fixes #2078
Bug-Debian: https://bugs.debian.org/716613

svn path=/trunk/vorbis/; revision=19422

lib/vorbisenc.c

index 428d2aa..7e448cd 100644 (file)
@@ -903,6 +903,8 @@ int vorbis_encode_setup_vbr(vorbis_info *vi,
                             long  channels,
                             long  rate,
                             float quality){
+  if(rate <= 0) return OV_EINVAL;
+
   codec_setup_info *ci=vi->codec_setup;
   highlevel_encode_setup *hi=&ci->hi;
 
@@ -948,6 +950,8 @@ int vorbis_encode_setup_managed(vorbis_info *vi,
                                 long nominal_bitrate,
                                 long min_bitrate){
 
+  if(rate <= 0) return OV_EINVAL;
+
   codec_setup_info *ci=vi->codec_setup;
   highlevel_encode_setup *hi=&ci->hi;
   double tnominal=nominal_bitrate;