Mercurial > libavcodec.hg
comparison libvorbis.c @ 12133:24649290a14f libavcodec
add some buffer checks
author | skal |
---|---|
date | Sun, 11 Jul 2010 06:59:21 +0000 |
parents | 189c04335897 |
children | a2c993c7ae90 |
comparison
equal
deleted
inserted
replaced
12132:189c04335897 | 12133:24649290a14f |
---|---|
170 while(vorbis_bitrate_flushpacket(&context->vd, &op)) { | 170 while(vorbis_bitrate_flushpacket(&context->vd, &op)) { |
171 /* i'd love to say the following line is a hack, but sadly it's | 171 /* i'd love to say the following line is a hack, but sadly it's |
172 * not, apparently the end of stream decision is in libogg. */ | 172 * not, apparently the end of stream decision is in libogg. */ |
173 if(op.bytes==1 && op.e_o_s) | 173 if(op.bytes==1 && op.e_o_s) |
174 continue; | 174 continue; |
175 if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) { | |
176 av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow."); | |
177 return -1; | |
178 } | |
175 memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet)); | 179 memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet)); |
176 context->buffer_index += sizeof(ogg_packet); | 180 context->buffer_index += sizeof(ogg_packet); |
177 memcpy(context->buffer + context->buffer_index, op.packet, op.bytes); | 181 memcpy(context->buffer + context->buffer_index, op.packet, op.bytes); |
178 context->buffer_index += op.bytes; | 182 context->buffer_index += op.bytes; |
179 // av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes); | 183 // av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes); |
186 op2->packet = context->buffer + sizeof(ogg_packet); | 190 op2->packet = context->buffer + sizeof(ogg_packet); |
187 | 191 |
188 l= op2->bytes; | 192 l= op2->bytes; |
189 avccontext->coded_frame->pts= av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base); | 193 avccontext->coded_frame->pts= av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base); |
190 //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate | 194 //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate |
195 | |
196 if (l > buf_size) { | |
197 av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow."); | |
198 return -1; | |
199 } | |
191 | 200 |
192 memcpy(packets, op2->packet, l); | 201 memcpy(packets, op2->packet, l); |
193 context->buffer_index -= l + sizeof(ogg_packet); | 202 context->buffer_index -= l + sizeof(ogg_packet); |
194 memmove(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); | 203 memmove(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); |
195 // av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); | 204 // av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); |