comparison vorbis.c @ 9934:ff96ee73b08b libavcodec

Add extra validation checks to ff_vorbis_len2vlc. They should not be necessary, but it seems like a reasonable precaution.
author reimar
date Wed, 08 Jul 2009 19:39:23 +0000
parents 0dce4fe6e6f3
children 76eeb9e3599b
comparison
equal deleted inserted replaced
9933:6fd0b776f838 9934:ff96ee73b08b
43 return ret - 1; 43 return ret - 1;
44 } 44 }
45 45
46 // Generate vlc codes from vorbis huffman code lengths 46 // Generate vlc codes from vorbis huffman code lengths
47 47
48 // the two bits[p] > 32 checks should be redundant, all calling code should
49 // already ensure that, but since it allows overwriting the stack it seems
50 // reasonable to check redundantly.
48 int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) { 51 int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) {
49 uint_fast32_t exit_at_level[33]={404,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 52 uint_fast32_t exit_at_level[33]={404,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
50 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 53 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
51 54
52 uint_fast8_t i,j; 55 uint_fast8_t i,j;
61 // av_log(vc->avccontext, AV_LOG_INFO, "An empty codebook. Heh?! \n"); 64 // av_log(vc->avccontext, AV_LOG_INFO, "An empty codebook. Heh?! \n");
62 return 0; 65 return 0;
63 } 66 }
64 67
65 codes[p]=0; 68 codes[p]=0;
69 if (bits[p] > 32) return 1;
66 for(i=0;i<bits[p];++i) { 70 for(i=0;i<bits[p];++i) {
67 exit_at_level[i+1]=1<<i; 71 exit_at_level[i+1]=1<<i;
68 } 72 }
69 73
70 #ifdef V_DEBUG 74 #ifdef V_DEBUG
77 #endif 81 #endif
78 82
79 ++p; 83 ++p;
80 84
81 for(;p<num;++p) { 85 for(;p<num;++p) {
86 if (bits[p] > 32) return 1;
82 if (bits[p]==0) continue; 87 if (bits[p]==0) continue;
83 // find corresponding exit(node which the tree can grow further from) 88 // find corresponding exit(node which the tree can grow further from)
84 for(i=bits[p];i>0;--i) { 89 for(i=bits[p];i>0;--i) {
85 if (exit_at_level[i]) break; 90 if (exit_at_level[i]) break;
86 } 91 }