comparison avidec.c @ 5149:4a53fcd622ea libavformat

Check for seek failures in avi_load_index, otherwise if the index offset is invalid (e.g. truncated file) we might end up reading the whole file since trying to seek beyond the end of file does not set EOF.
author reimar
date Wed, 26 Aug 2009 08:38:44 +0000
parents b0706c2efb78
children 1258b5879021
comparison
equal deleted inserted replaced
5148:74d599c373f9 5149:4a53fcd622ea
999 { 999 {
1000 AVIContext *avi = s->priv_data; 1000 AVIContext *avi = s->priv_data;
1001 ByteIOContext *pb = s->pb; 1001 ByteIOContext *pb = s->pb;
1002 uint32_t tag, size; 1002 uint32_t tag, size;
1003 int64_t pos= url_ftell(pb); 1003 int64_t pos= url_ftell(pb);
1004 1004 int ret = -1;
1005 url_fseek(pb, avi->movi_end, SEEK_SET); 1005
1006 if (url_fseek(pb, avi->movi_end, SEEK_SET) < 0)
1007 goto the_end; // maybe truncated file
1006 #ifdef DEBUG_SEEK 1008 #ifdef DEBUG_SEEK
1007 printf("movi_end=0x%"PRIx64"\n", avi->movi_end); 1009 printf("movi_end=0x%"PRIx64"\n", avi->movi_end);
1008 #endif 1010 #endif
1009 for(;;) { 1011 for(;;) {
1010 if (url_feof(pb)) 1012 if (url_feof(pb))
1021 #endif 1023 #endif
1022 switch(tag) { 1024 switch(tag) {
1023 case MKTAG('i', 'd', 'x', '1'): 1025 case MKTAG('i', 'd', 'x', '1'):
1024 if (avi_read_idx1(s, size) < 0) 1026 if (avi_read_idx1(s, size) < 0)
1025 goto skip; 1027 goto skip;
1026 else 1028 ret = 0;
1027 goto the_end; 1029 goto the_end;
1028 break; 1030 break;
1029 default: 1031 default:
1030 skip: 1032 skip:
1031 size += (size & 1); 1033 size += (size & 1);
1032 url_fskip(pb, size); 1034 if (url_fseek(pb, size, SEEK_CUR) < 0)
1035 goto the_end; // something is wrong here
1033 break; 1036 break;
1034 } 1037 }
1035 } 1038 }
1036 the_end: 1039 the_end:
1037 url_fseek(pb, pos, SEEK_SET); 1040 url_fseek(pb, pos, SEEK_SET);
1038 return 0; 1041 return ret;
1039 } 1042 }
1040 1043
1041 static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) 1044 static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
1042 { 1045 {
1043 AVIContext *avi = s->priv_data; 1046 AVIContext *avi = s->priv_data;