MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / parse_utf

Function parse_utf

libavformat/usmdec.c:73–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73static int parse_utf(AVFormatContext *s, AVIOContext *pb,
74 USMChannel *ch, int ch_type,
75 uint32_t parent_chunk_size)
76{
77 USMDemuxContext *usm = s->priv_data;
78 GetByteContext gb, ugb, sgb;
79 uint32_t chunk_type, chunk_size, offset;
80 uint32_t unique_offset, string_offset;
81 int nb_items, unique_size, nb_dictionaries;
82 AVRational fps = { 0 };
83 int type;
84
85 chunk_type = avio_rb32(pb);
86 chunk_size = avio_rb32(pb);
87
88 if (chunk_type != MKBETAG('@','U','T','F'))
89 return AVERROR_INVALIDDATA;
90
91 if (!chunk_size || chunk_size >= parent_chunk_size)
92 return AVERROR_INVALIDDATA;
93
94 av_fast_malloc(&usm->header, &usm->header_size, chunk_size);
95 if (!usm->header)
96 return AVERROR(ENOMEM);
97
98 if (avio_read(pb, usm->header, chunk_size) != chunk_size)
99 return AVERROR_EOF;
100
101 bytestream2_init(&gb, usm->header, chunk_size);
102 ugb = gb;
103 sgb = gb;
104 unique_offset = bytestream2_get_be32(&gb);
105 string_offset = bytestream2_get_be32(&gb);
106 /*byte_offset =*/ bytestream2_get_be32(&gb);
107 /*payload_name_offset =*/ bytestream2_get_be32(&gb);
108 nb_items = bytestream2_get_be16(&gb);
109 unique_size = bytestream2_get_be16(&gb);
110 nb_dictionaries = bytestream2_get_be32(&gb);
111 if (nb_dictionaries == 0)
112 return AVERROR_INVALIDDATA;
113
114 bytestream2_skip(&ugb, unique_offset);
115 if (bytestream2_get_bytes_left(&ugb) < unique_size)
116 return AVERROR_INVALIDDATA;
117 bytestream2_init(&ugb, ugb.buffer, unique_size);
118
119 bytestream2_skip(&sgb, string_offset);
120
121 for (int i = 0; i < nb_items; i++) {
122 GetByteContext *xgb;
123 uint8_t key[256];
124 int64_t value = -1;
125 int n = 0;
126
127 type = bytestream2_get_byte(&gb);
128 offset = bytestream2_get_be32(&gb);
129
130 bytestream2_seek(&sgb, string_offset + offset, SEEK_SET);

Callers 1

parse_chunkFunction · 0.85

Calls 10

avio_rb32Function · 0.85
av_fast_mallocFunction · 0.85
avio_readFunction · 0.85
bytestream2_initFunction · 0.85
bytestream2_skipFunction · 0.85
bytestream2_seekFunction · 0.85
av_int2floatFunction · 0.85
av_int2doubleFunction · 0.85
av_logFunction · 0.85

Tested by

no test coverage detected