Revision 93b78d12 libavformat/asfdec.c

View differences:

libavformat/asfdec.c
121 121
}
122 122
#endif
123 123

  
124
static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
125
{
126
    char* q = buf;
127
    while (len > 1) {
128
        uint8_t tmp;
129
        uint32_t ch;
130

  
131
        GET_UTF16(ch, (len -= 2) >= 0 ? get_le16(pb) : 0, break;)
132
        PUT_UTF8(ch, tmp, if (q - buf < buf_size - 1) *q++ = tmp;)
133
    }
134
    if (len > 0)
135
        url_fskip(pb, len);
136
    *q = '\0';
137
}
138

  
139 124
static int asf_probe(AVProbeData *pd)
140 125
{
141 126
    /* check file header */
......
167 152
        return;
168 153

  
169 154
    if (type == 0) {         // UTF16-LE
170
        get_str16_nolen(s->pb, len, value, 2*len + 1);
155
        avio_get_str16le(s->pb, len, value, 2*len + 1);
171 156
    } else if (type > 1 && type <= 5) {  // boolean or DWORD or QWORD or WORD
172 157
        uint64_t num = get_value(s->pb, type);
173 158
        snprintf(value, len, "%"PRIu64, num);
......
206 191
    memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
207 192
    for(;;) {
208 193
        uint64_t gpos= url_ftell(pb);
194
        int ret;
209 195
        ff_get_guid(pb, &g);
210 196
        gsize = get_le64(pb);
211 197
        dprintf(s, "%08"PRIx64": ", gpos);
......
447 433
            for(j = 0; j < stream_count; j++) {
448 434
                char lang[6];
449 435
                unsigned int lang_len = get_byte(pb);
450
                get_str16_nolen(pb, lang_len, lang, sizeof(lang));
436
                if ((ret = avio_get_str16le(pb, lang_len, lang, sizeof(lang))) < lang_len)
437
                    url_fskip(pb, lang_len - ret);
451 438
                if (j < 128)
452 439
                    av_strlcpy(asf->stream_languages[j], lang, sizeof(*asf->stream_languages));
453 440
            }
......
462 449
                    name_len = get_le16(pb);
463 450
                    if (name_len%2)     // must be even, broken lavf versions wrote len-1
464 451
                        name_len += 1;
465
                    get_str16_nolen(pb, name_len, name, sizeof(name));
452
                    if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
453
                        url_fskip(pb, name_len - ret);
466 454
                    value_type = get_le16(pb);
467 455
                    value_len  = get_le16(pb);
468 456
                    if (!value_type && value_len%2)
......
491 479
                value_type= get_le16(pb);
492 480
                value_len=  get_le32(pb);
493 481

  
494
                get_str16_nolen(pb, name_len, name, sizeof(name));
482
                if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
483
                    url_fskip(pb, name_len - ret);
495 484
//av_log(s, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
496 485
                value_num= get_le16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
497 486
                url_fskip(pb, value_len - 2);
......
574 563
                get_le32(pb);             // send time
575 564
                get_le32(pb);             // flags
576 565
                name_len = get_le32(pb);  // name length
577
                get_str16_nolen(pb, name_len * 2, name, sizeof(name));
566
                if ((ret = avio_get_str16le(pb, name_len * 2, name, sizeof(name))) < name_len)
567
                    url_fskip(pb, name_len - ret);
578 568
                ff_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name );
579 569
            }
580 570
#if 0

Also available in: Unified diff