comparison flacdec.c @ 9119:f3d87e34599f libavcodec

flacdec: Check for an inline header before calling metadata_parse().
author jbr
date Wed, 04 Mar 2009 00:52:18 +0000
parents f13d019e004a
children dfd80d6fabfe
comparison
equal deleted inserted replaced
9118:f13d019e004a 9119:f3d87e34599f
222 /** 222 /**
223 * Parse a list of metadata blocks. This list of blocks must begin with 223 * Parse a list of metadata blocks. This list of blocks must begin with
224 * the fLaC marker. 224 * the fLaC marker.
225 * @param s the flac decoding context containing the gb bit reader used to 225 * @param s the flac decoding context containing the gb bit reader used to
226 * parse metadata 226 * parse metadata
227 * @return 1 if some metadata was read, 0 if no fLaC marker was found 227 * @return non-zero if metadata is invalid
228 */ 228 */
229 static int metadata_parse(FLACContext *s) 229 static int metadata_parse(FLACContext *s)
230 { 230 {
231 int i, metadata_last, metadata_type, metadata_size; 231 int i, metadata_last, metadata_type, metadata_size;
232 int initial_pos= get_bits_count(&s->gb); 232 int initial_pos= get_bits_count(&s->gb);
233 233
234 if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) {
235 skip_bits_long(&s->gb, 32); 234 skip_bits_long(&s->gb, 32);
236 235
237 do { 236 do {
238 metadata_last = get_bits1(&s->gb); 237 metadata_last = get_bits1(&s->gb);
239 metadata_type = get_bits(&s->gb, 7); 238 metadata_type = get_bits(&s->gb, 7);
258 skip_bits(&s->gb, 8); 257 skip_bits(&s->gb, 8);
259 } 258 }
260 } 259 }
261 } while (!metadata_last); 260 } while (!metadata_last);
262 261
263 return 1;
264 }
265 return 0; 262 return 0;
266 } 263 }
267 264
268 static int decode_residuals(FLACContext *s, int channel, int pred_order) 265 static int decode_residuals(FLACContext *s, int channel, int pred_order)
269 { 266 {
640 } 637 }
641 } 638 }
642 639
643 init_get_bits(&s->gb, buf, buf_size*8); 640 init_get_bits(&s->gb, buf, buf_size*8);
644 641
645 if (metadata_parse(s)) 642 /* check for inline header */
643 if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) {
644 if (metadata_parse(s)) {
645 av_log(s->avctx, AV_LOG_ERROR, "invalid header\n");
646 return -1;
647 }
646 goto end; 648 goto end;
649 }
647 650
648 tmp = show_bits(&s->gb, 16); 651 tmp = show_bits(&s->gb, 16);
649 if ((tmp & 0xFFFE) != 0xFFF8) { 652 if ((tmp & 0xFFFE) != 0xFFF8) {
650 av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n"); 653 av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n");
651 while (get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8) 654 while (get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8)