ref: f6963f289a4644bc11ab68934b9ce2df870a8516
parent: cf2ed506f1f5c61bdd25a443f81faef3428f0d98
author: Gregory Maxwell <greg@xiph.org>
date: Thu Nov 27 16:17:54 EST 2014
opusenc: reject sampling rates over 768KHz or under 100Hz. Crazy sampling rates cause unreasonable memory usage. This also moves lpc.c temporary buffers onto the heap, we use them once per file, so the additional malloc activity is not a concern. Thanks to Dennis Felsing for the report and example inputs.
--- a/src/lpc.c
+++ b/src/lpc.c
@@ -50,7 +50,6 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
-#include "stack_alloc.h"
#include "lpc.h"
/* Autocorrelation LPC coeff generation algorithm invented by
@@ -60,8 +59,8 @@
Output: m lpc coefficients, excitation energy */
float vorbis_lpc_from_data(float *data,float *lpci,int n,int m,int stride){
- double *aut=alloca(sizeof(*aut)*(m+1));
- double *lpc=alloca(sizeof(*lpc)*(m));
+ double *aut=malloc(sizeof(*aut)*(m+1));
+ double *lpc=malloc(sizeof(*lpc)*(m));
double error;
double epsilon;
int i,j;
@@ -127,7 +126,8 @@
/* we need the error value to know how big an impulse to hit the
filter with later */
-
+ free(aut);
+ free(lpc);
return error;
}
@@ -140,7 +140,7 @@
long i,j,o,p;
float y;
- float *work=alloca(sizeof(*work)*(m+n));
+ float *work=malloc(sizeof(*work)*(m+n));
if(!prime)
for(i=0;i<m;i++)
@@ -158,4 +158,5 @@
data[i*stride]=work[o]=y;
}
+ free(work);
}
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -642,6 +642,17 @@
exit(1);
}
+ if(inopt.rate<100||inopt.rate>768000){
+ /*Crazy rates excluded to avoid excessive memory usage for padding/resampling.*/
+ fprintf(stderr,"Error parsing input file: %s unhandled sampling rate: %ld hz\n",inFile,inopt.rate);
+ exit(1);
+ }
+
+ if(inopt.channels>255||inopt.channels<1){
+ fprintf(stderr,"Error parsing input file: %s unhandled number of channels: %d\n",inFile,inopt.channels);
+ exit(1);
+ }
+
if(downmix==0&&inopt.channels>2&&bitrate>0&&bitrate<(16000*inopt.channels)){
if(!quiet)fprintf(stderr,"Notice: Surround bitrate less than 16kbit/sec/channel, downmixing.\n");
downmix=inopt.channels>8?1:2;