[libvorbis] Allocate memory with _ogg_malloc

See https://gitlab.xiph.org/xiph/vorbis/-/commit/28965ede851bb9c1ce5cc0ed733fdf4ebd3d4241 and related commits.
This commit is contained in:
Moonchild
2026-05-25 11:44:16 +02:00
committed by roytam1
parent 4bf236902c
commit e9c3451d54
+30 -3
View File
@@ -352,9 +352,13 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
/* perform sort */
ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
ogg_uint32_t **codep=alloca(sizeof(*codep)*n);
ogg_uint32_t **codep=_ogg_malloc(sizeof(*codep)*n);
if(codes==NULL)goto err_out;
if(codes==NULL || codep==NULL){
if(codes)_ogg_free(codes);
if(codep)_ogg_free(codep);
goto err_out;
}
for(i=0;i<n;i++){
codes[i]=bitreverse(codes[i]);
@@ -363,13 +367,25 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
qsort(codep,n,sizeof(*codep),sort32a);
sortindex=alloca(n*sizeof(*sortindex));
sortindex=_ogg_malloc(n*sizeof(*sortindex));
if(sortindex==NULL){
_ogg_free(codes);
_ogg_free(codep);
goto err_out;
}
c->codelist=_ogg_malloc(n*sizeof(*c->codelist));
if(c->codelist==NULL){
_ogg_free(sortindex);
_ogg_free(codep);
_ogg_free(codes);
goto err_out;
}
/* the index is a reverse index */
for(i=0;i<n;i++){
int position=codep[i]-codes;
sortindex[position]=i;
}
_ogg_free(codep);
for(i=0;i<n;i++)
c->codelist[sortindex[i]]=codes[i];
@@ -377,12 +393,20 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
c->valuelist=_book_unquantize(s,n,sortindex);
c->dec_index=_ogg_malloc(n*sizeof(*c->dec_index));
if(c->dec_index==NULL){
_ogg_free(sortindex);
goto err_out;
}
for(n=0,i=0;i<s->entries;i++)
if(s->lengthlist[i]>0)
c->dec_index[sortindex[n++]]=i;
c->dec_codelengths=_ogg_malloc(n*sizeof(*c->dec_codelengths));
if(c->dec_codelengths==NULL){
_ogg_free(sortindex);
goto err_out;
}
c->dec_maxlength=0;
for(n=0,i=0;i<s->entries;i++)
if(s->lengthlist[i]>0){
@@ -390,6 +414,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
if(s->lengthlist[i]>c->dec_maxlength)
c->dec_maxlength=s->lengthlist[i];
}
_ogg_free(sortindex);
if(n==1 && c->dec_maxlength==1){
/* special case the 'single entry codebook' with a single bit
@@ -397,6 +422,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
unmodified decode paths. */
c->dec_firsttablen=1;
c->dec_firsttable=_ogg_calloc(2,sizeof(*c->dec_firsttable));
if(c->dec_firsttable==NULL)goto err_out;
c->dec_firsttable[0]=c->dec_firsttable[1]=1;
}else{
@@ -406,6 +432,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){
tabn=1<<c->dec_firsttablen;
c->dec_firsttable=_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
if(c->dec_firsttable==NULL)goto err_out;
for(i=0;i<n;i++){
if(c->dec_codelengths[i]<=c->dec_firsttablen){