Mercurial > libavcodec.hg
comparison aacenc.c @ 9941:a7b6bbf19002 libavcodec
Prevent AAC frame size overflows.
author | alexc |
---|---|
date | Wed, 08 Jul 2009 23:12:53 +0000 |
parents | 580fad942ae6 |
children | f91d6810f983 |
comparison
equal
deleted
inserted
replaced
9940:580fad942ae6 | 9941:a7b6bbf19002 |
---|---|
538 s->cur_channel = start_ch + j; | 538 s->cur_channel = start_ch + j; |
539 apply_window_and_mdct(avctx, s, &cpe->ch[j], samples2, j); | 539 apply_window_and_mdct(avctx, s, &cpe->ch[j], samples2, j); |
540 } | 540 } |
541 start_ch += chans; | 541 start_ch += chans; |
542 } | 542 } |
543 do { | |
544 int frame_bits; | |
543 init_put_bits(&s->pb, frame, buf_size*8); | 545 init_put_bits(&s->pb, frame, buf_size*8); |
544 if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT)) | 546 if ((avctx->frame_number & 0xFF)==1 && !(avctx->flags & CODEC_FLAG_BITEXACT)) |
545 put_bitstream_info(avctx, s, LIBAVCODEC_IDENT); | 547 put_bitstream_info(avctx, s, LIBAVCODEC_IDENT); |
546 start_ch = 0; | 548 start_ch = 0; |
547 memset(chan_el_counter, 0, sizeof(chan_el_counter)); | 549 memset(chan_el_counter, 0, sizeof(chan_el_counter)); |
584 encode_individual_channel(avctx, s, &cpe->ch[j], cpe->common_window); | 586 encode_individual_channel(avctx, s, &cpe->ch[j], cpe->common_window); |
585 } | 587 } |
586 start_ch += chans; | 588 start_ch += chans; |
587 } | 589 } |
588 | 590 |
591 frame_bits = put_bits_count(&s->pb); | |
592 if (frame_bits <= 6144 * avctx->channels - 3) | |
593 break; | |
594 | |
595 s->lambda *= avctx->bit_rate * 1024.0f / avctx->sample_rate / frame_bits; | |
596 | |
597 } while (1); | |
598 | |
589 put_bits(&s->pb, 3, TYPE_END); | 599 put_bits(&s->pb, 3, TYPE_END); |
590 flush_put_bits(&s->pb); | 600 flush_put_bits(&s->pb); |
591 avctx->frame_bits = put_bits_count(&s->pb); | 601 avctx->frame_bits = put_bits_count(&s->pb); |
592 | 602 |
593 // rate control stuff | 603 // rate control stuff |
594 if (!(avctx->flags & CODEC_FLAG_QSCALE)) { | 604 if (!(avctx->flags & CODEC_FLAG_QSCALE)) { |
595 float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / avctx->frame_bits; | 605 float ratio = avctx->bit_rate * 1024.0f / avctx->sample_rate / avctx->frame_bits; |
596 s->lambda *= ratio; | 606 s->lambda *= ratio; |
597 s->lambda = fminf(s->lambda, 65536.f); | 607 s->lambda = fminf(s->lambda, 65536.f); |
598 } | 608 } |
599 | |
600 if (avctx->frame_bits > 6144*avctx->channels) | |
601 av_log(avctx, AV_LOG_ERROR, "input buffer violation %d > %d.\n", | |
602 avctx->frame_bits, 6144*avctx->channels); | |
603 | 609 |
604 if (!data) | 610 if (!data) |
605 s->last_frame = 1; | 611 s->last_frame = 1; |
606 memcpy(s->samples, s->samples + 1024 * avctx->channels, | 612 memcpy(s->samples, s->samples + 1024 * avctx->channels, |
607 1024 * avctx->channels * sizeof(s->samples[0])); | 613 1024 * avctx->channels * sizeof(s->samples[0])); |