Mercurial > libavcodec.hg
comparison flacdec.c @ 9233:8aa63f696237 libavcodec
flacdec: move data size check to flac_decode_frame()
author | jbr |
---|---|
date | Sun, 22 Mar 2009 20:19:20 +0000 |
parents | 2c3b2ce51b04 |
children | df759d70d6f9 |
comparison
equal
deleted
inserted
replaced
9232:2c3b2ce51b04 | 9233:8aa63f696237 |
---|---|
478 } | 478 } |
479 | 479 |
480 return 0; | 480 return 0; |
481 } | 481 } |
482 | 482 |
483 static int decode_frame(FLACContext *s, int alloc_data_size) | 483 static int decode_frame(FLACContext *s) |
484 { | 484 { |
485 int bs_code, sr_code, bps_code, i; | 485 int bs_code, sr_code, bps_code, i; |
486 int ch_mode, bps, blocksize, samplerate; | 486 int ch_mode, bps, blocksize, samplerate; |
487 GetBitContext *gb = &s->gb; | 487 GetBitContext *gb = &s->gb; |
488 | 488 |
551 if (blocksize > s->max_blocksize) { | 551 if (blocksize > s->max_blocksize) { |
552 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, | 552 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, |
553 s->max_blocksize); | 553 s->max_blocksize); |
554 return -1; | 554 return -1; |
555 } | 555 } |
556 | |
557 if (blocksize * s->channels * (s->is32 ? 4 : 2) > alloc_data_size) | |
558 return -1; | |
559 | 556 |
560 /* sample rate */ | 557 /* sample rate */ |
561 if (sr_code == 0) | 558 if (sr_code == 0) |
562 samplerate= s->samplerate; | 559 samplerate= s->samplerate; |
563 else if (sr_code < 12) | 560 else if (sr_code < 12) |
610 FLACContext *s = avctx->priv_data; | 607 FLACContext *s = avctx->priv_data; |
611 int i, j = 0, input_buf_size = 0, bytes_read = 0; | 608 int i, j = 0, input_buf_size = 0, bytes_read = 0; |
612 int16_t *samples_16 = data; | 609 int16_t *samples_16 = data; |
613 int32_t *samples_32 = data; | 610 int32_t *samples_32 = data; |
614 int alloc_data_size= *data_size; | 611 int alloc_data_size= *data_size; |
612 int output_size; | |
615 | 613 |
616 *data_size=0; | 614 *data_size=0; |
617 | 615 |
618 if (s->max_framesize == 0) { | 616 if (s->max_framesize == 0) { |
619 s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header | 617 s->max_framesize= FFMAX(4, buf_size); // should hopefully be enough for the first header |
673 goto end; // we may not have enough bits left to decode a frame, so try next time | 671 goto end; // we may not have enough bits left to decode a frame, so try next time |
674 } | 672 } |
675 | 673 |
676 /* decode frame */ | 674 /* decode frame */ |
677 init_get_bits(&s->gb, buf, buf_size*8); | 675 init_get_bits(&s->gb, buf, buf_size*8); |
678 if (decode_frame(s, alloc_data_size) < 0) { | 676 if (decode_frame(s) < 0) { |
679 av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); | 677 av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); |
680 s->bitstream_size=0; | 678 s->bitstream_size=0; |
681 s->bitstream_index=0; | 679 s->bitstream_index=0; |
682 return -1; | 680 return -1; |
683 } | 681 } |
684 *data_size = s->blocksize * s->channels * (s->is32 ? 4 : 2); | |
685 bytes_read = (get_bits_count(&s->gb)+7)/8; | 682 bytes_read = (get_bits_count(&s->gb)+7)/8; |
683 | |
684 /* check if allocated data size is large enough for output */ | |
685 output_size = s->blocksize * s->channels * (s->is32 ? 4 : 2); | |
686 if (output_size > alloc_data_size) { | |
687 av_log(s->avctx, AV_LOG_ERROR, "output data size is larger than " | |
688 "allocated data size\n"); | |
689 return -1; | |
690 } | |
691 *data_size = output_size; | |
686 | 692 |
687 #define DECORRELATE(left, right)\ | 693 #define DECORRELATE(left, right)\ |
688 assert(s->channels == 2);\ | 694 assert(s->channels == 2);\ |
689 for (i = 0; i < s->blocksize; i++) {\ | 695 for (i = 0; i < s->blocksize; i++) {\ |
690 int a= s->decoded[0][i];\ | 696 int a= s->decoded[0][i];\ |