00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "libavutil/intreadwrite.h"
00022 #include "xiph.h"
00023
00024 int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size,
00025 int first_header_size, uint8_t *header_start[3],
00026 int header_len[3])
00027 {
00028 int i;
00029
00030 if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) {
00031 int overall_len = 6;
00032 for (i=0; i<3; i++) {
00033 header_len[i] = AV_RB16(extradata);
00034 extradata += 2;
00035 header_start[i] = extradata;
00036 extradata += header_len[i];
00037 if (overall_len > extradata_size - header_len[i])
00038 return -1;
00039 overall_len += header_len[i];
00040 }
00041 } else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) {
00042 int overall_len = 3;
00043 extradata++;
00044 for (i=0; i<2; i++, extradata++) {
00045 header_len[i] = 0;
00046 for (; overall_len < extradata_size && *extradata==0xff; extradata++) {
00047 header_len[i] += 0xff;
00048 overall_len += 0xff + 1;
00049 }
00050 header_len[i] += *extradata;
00051 overall_len += *extradata;
00052 if (overall_len > extradata_size)
00053 return -1;
00054 }
00055 header_len[2] = extradata_size - overall_len;
00056 header_start[0] = extradata;
00057 header_start[1] = header_start[0] + header_len[0];
00058 header_start[2] = header_start[1] + header_len[1];
00059 } else {
00060 return -1;
00061 }
00062 return 0;
00063 }