Revision 93b78d12

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
libavformat/avio.h
460 460
uint64_t get_le64(ByteIOContext *s);
461 461
unsigned int get_le16(ByteIOContext *s);
462 462

  
463
/**
464
 * Read a UTF-16 string from pb and convert it to UTF-8.
465
 * The reading will terminate when either a null or invalid character was
466
 * encountered or maxlen bytes have been read.
467
 * @return number of bytes read (is always <= maxlen)
468
 */
469
int avio_get_str16le(ByteIOContext *pb, int maxlen, char *buf, int buflen);
470
int avio_get_str16be(ByteIOContext *pb, int maxlen, char *buf, int buflen);
471

  
463 472
char *get_strz(ByteIOContext *s, char *buf, int maxlen);
464 473
unsigned int get_be16(ByteIOContext *s);
465 474
unsigned int get_be24(ByteIOContext *s);
libavformat/aviobuf.c
602 602
    return i;
603 603
}
604 604

  
605
#define GET_STR16(type, read) \
606
    int avio_get_str16 ##type(ByteIOContext *pb, int maxlen, char *buf, int buflen)\
607
{\
608
    char* q = buf;\
609
    int ret = 0;\
610
    while (ret + 1 < maxlen) {\
611
        uint8_t tmp;\
612
        uint32_t ch;\
613
        GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
614
        if (!ch)\
615
            break;\
616
        PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
617
    }\
618
    *q = 0;\
619
    return ret;\
620
}\
621

  
622
GET_STR16(le, get_le16)
623
GET_STR16(be, get_be16)
624

  
625
#undef GET_STR16
626

  
605 627
uint64_t get_be64(ByteIOContext *s)
606 628
{
607 629
    uint64_t val;

Also available in: Unified diff