Mercurial > libavformat.hg
comparison nutdec.c @ 3377:7b34cd9dfe85 libavformat
Fix memleak, fixed CID123.
author | michael |
---|---|
date | Tue, 27 May 2008 20:48:27 +0000 |
parents | 7a823a401282 |
children | 7a0230981402 |
comparison
equal
deleted
inserted
replaced
3376:7db242158d51 | 3377:7b34cd9dfe85 |
---|---|
498 uint64_t tmp, end; | 498 uint64_t tmp, end; |
499 int i, j, syncpoint_count; | 499 int i, j, syncpoint_count; |
500 int64_t filesize= url_fsize(bc); | 500 int64_t filesize= url_fsize(bc); |
501 int64_t *syncpoints; | 501 int64_t *syncpoints; |
502 int8_t *has_keyframe; | 502 int8_t *has_keyframe; |
503 int ret= -1; | |
503 | 504 |
504 url_fseek(bc, filesize-12, SEEK_SET); | 505 url_fseek(bc, filesize-12, SEEK_SET); |
505 url_fseek(bc, filesize-get_be64(bc), SEEK_SET); | 506 url_fseek(bc, filesize-get_be64(bc), SEEK_SET); |
506 if(get_be64(bc) != INDEX_STARTCODE){ | 507 if(get_be64(bc) != INDEX_STARTCODE){ |
507 av_log(s, AV_LOG_ERROR, "no index at the end\n"); | 508 av_log(s, AV_LOG_ERROR, "no index at the end\n"); |
514 ff_get_v(bc); //max_pts | 515 ff_get_v(bc); //max_pts |
515 GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0) | 516 GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0) |
516 syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count); | 517 syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count); |
517 has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1)); | 518 has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1)); |
518 for(i=0; i<syncpoint_count; i++){ | 519 for(i=0; i<syncpoint_count; i++){ |
519 GET_V(syncpoints[i], tmp>0) | 520 syncpoints[i] = ff_get_v(bc); |
521 if(syncpoints[i] <= 0) | |
522 goto fail; | |
520 if(i) | 523 if(i) |
521 syncpoints[i] += syncpoints[i-1]; | 524 syncpoints[i] += syncpoints[i-1]; |
522 } | 525 } |
523 | 526 |
524 for(i=0; i<s->nb_streams; i++){ | 527 for(i=0; i<s->nb_streams; i++){ |
531 if(type){ | 534 if(type){ |
532 int flag= x&1; | 535 int flag= x&1; |
533 x>>=1; | 536 x>>=1; |
534 if(n+x >= syncpoint_count + 1){ | 537 if(n+x >= syncpoint_count + 1){ |
535 av_log(s, AV_LOG_ERROR, "index overflow A\n"); | 538 av_log(s, AV_LOG_ERROR, "index overflow A\n"); |
536 return -1; | 539 goto fail; |
537 } | 540 } |
538 while(x--) | 541 while(x--) |
539 has_keyframe[n++]= flag; | 542 has_keyframe[n++]= flag; |
540 has_keyframe[n++]= !flag; | 543 has_keyframe[n++]= !flag; |
541 }else{ | 544 }else{ |
542 while(x != 1){ | 545 while(x != 1){ |
543 if(n>=syncpoint_count + 1){ | 546 if(n>=syncpoint_count + 1){ |
544 av_log(s, AV_LOG_ERROR, "index overflow B\n"); | 547 av_log(s, AV_LOG_ERROR, "index overflow B\n"); |
545 return -1; | 548 goto fail; |
546 } | 549 } |
547 has_keyframe[n++]= x&1; | 550 has_keyframe[n++]= x&1; |
548 x>>=1; | 551 x>>=1; |
549 } | 552 } |
550 } | 553 } |
551 if(has_keyframe[0]){ | 554 if(has_keyframe[0]){ |
552 av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n"); | 555 av_log(s, AV_LOG_ERROR, "keyframe before first syncpoint in index\n"); |
553 return -1; | 556 goto fail; |
554 } | 557 } |
555 assert(n<=syncpoint_count+1); | 558 assert(n<=syncpoint_count+1); |
556 for(; j<n && j<syncpoint_count; j++){ | 559 for(; j<n && j<syncpoint_count; j++){ |
557 if(has_keyframe[j]){ | 560 if(has_keyframe[j]){ |
558 uint64_t B, A= ff_get_v(bc); | 561 uint64_t B, A= ff_get_v(bc); |
575 } | 578 } |
576 } | 579 } |
577 | 580 |
578 if(skip_reserved(bc, end) || get_checksum(bc)){ | 581 if(skip_reserved(bc, end) || get_checksum(bc)){ |
579 av_log(s, AV_LOG_ERROR, "index checksum mismatch\n"); | 582 av_log(s, AV_LOG_ERROR, "index checksum mismatch\n"); |
580 return -1; | 583 goto fail; |
581 } | 584 } |
582 return 0; | 585 ret= 0; |
586 fail: | |
587 av_free(syncpoints); | |
588 av_free(has_keyframe); | |
589 return ret; | |
583 } | 590 } |
584 | 591 |
585 static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) | 592 static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) |
586 { | 593 { |
587 NUTContext *nut = s->priv_data; | 594 NUTContext *nut = s->priv_data; |