History

adx: calculate the number of blocks in a packet

Justin Ruggles committed 14 years ago

Commit 7ff55d91 parent 05c1f111 file · +11 −2Browse files

Unified · Split

libavcodec/adxdec.c+11−2
@@ -122,6 +122,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 121 unmodified lines
122122 int16_t *samples = data;
123123 const uint8_t *buf = buf0;
124124 int rest = buf_size;
125+ int num_blocks;
125126
126127 if (!c->header_parsed) {
127128 int hdrsize = adx_decode_header(avctx, buf, rest);
@@ -136,8 +137,15 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 8 unmodified lines
136137
137138 /* 18 bytes of data are expanded into 32*2 bytes of audio,
138139 so guard against buffer overflows */
139− if (rest / (BLOCK_SIZE * c->channels) > *data_size / (BLOCK_SAMPLES * c->channels))
140+ num_blocks = (rest + c->in_temp) / (BLOCK_SIZE * c->channels);
141+ if (num_blocks > *data_size / (BLOCK_SAMPLES * c->channels)) {
140142 rest = (*data_size / (BLOCK_SAMPLES * c->channels)) * BLOCK_SIZE;
143+ num_blocks = (rest + c->in_temp) / (BLOCK_SIZE * c->channels);
144+ }
145+ if (!num_blocks) {
146+ av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
147+ return AVERROR_INVALIDDATA;
148+ }
141149
142150 if (c->in_temp) {
143151 int copysize = BLOCK_SIZE * avctx->channels - c->in_temp;
@@ -148,9 +156,10 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, · 4 unmodified lines
148156 if (avctx->channels == 2)
149157 adx_decode(c, samples + 1, c->dec_temp + BLOCK_SIZE, 1);
150158 samples += BLOCK_SAMPLES * c->channels;
159+ num_blocks--;
151160 }
152161
153− while (rest >= BLOCK_SIZE * c->channels) {
162+ while (num_blocks--) {
154163 adx_decode(c, samples, buf, 0);
155164 if (c->channels == 2)
156165 adx_decode(c, samples + 1, buf + BLOCK_SIZE, 1);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t