Revision 20c68378

View differences:

libavformat/id3v2.c
81 81
    char *q, dst[512];
82 82
    int len, dstlen = sizeof(dst) - 1;
83 83
    unsigned genre;
84
    unsigned int (*get)(ByteIOContext*) = get_be16;
84 85

  
85 86
    dst[0] = 0;
86 87
    if (taglen < 1)
......
99 100
        *q = 0;
100 101
        break;
101 102

  
103
    case 1:  /* UTF-16 with BOM */
104
        taglen -= 2;
105
        switch (get_be16(s->pb)) {
106
        case 0xfffe:
107
            get = get_le16;
108
        case 0xfeff:
109
            break;
110
        default:
111
            av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key);
112
            return;
113
        }
114
        // fall-through
115

  
116
    case 2:  /* UTF-16BE without BOM */
117
        q = dst;
118
        while (taglen > 1 && q - dst < dstlen - 7) {
119
            uint32_t ch;
120
            uint8_t tmp;
121

  
122
            GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;)
123
            PUT_UTF8(ch, tmp, *q++ = tmp;)
124
        }
125
        *q = 0;
126
        break;
127

  
102 128
    case 3:  /* UTF-8 */
103 129
        len = FFMIN(taglen, dstlen - 1);
104 130
        get_buffer(s->pb, dst, len);
105 131
        dst[len] = 0;
106 132
        break;
133
    default:
134
        av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key);
107 135
    }
108 136

  
109 137
    if (!strcmp(key, "genre")
libavutil/common.h
266 266
    }
267 267

  
268 268
/*!
269
 * \def GET_UTF16(val, GET_16BIT, ERROR)
270
 * Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form
271
 * \param val is the output and should be of type uint32_t. It holds the converted
272
 * UCS-4 character and should be a left value.
273
 * \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness.
274
 * It can be a function or a statement whose return value or evaluated value is of type
275
 * uint16_t. It will be executed up to 2 times.
276
 * \param ERROR action that should be taken when an invalid UTF-16 surrogate is
277
 * returned from GET_BYTE. It should be a statement that jumps out of the macro,
278
 * like exit(), goto, return, break, or continue.
279
 */
280
#define GET_UTF16(val, GET_16BIT, ERROR)\
281
    val = GET_16BIT;\
282
    {\
283
        unsigned int hi = val - 0xD800;\
284
        if (hi < 0x800) {\
285
            val = GET_16BIT - 0xDC00;\
286
            if (val > 0x3FFU || hi > 0x3FFU)\
287
                ERROR\
288
            val += (hi<<10) + 0x10000;\
289
        }\
290
    }\
291

  
292
/*!
269 293
 * \def PUT_UTF8(val, tmp, PUT_BYTE)
270 294
 * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
271 295
 * \param val is an input-only argument and should be of type uint32_t. It holds

Also available in: Unified diff