static int asf_read_value(AVFormatContext *s, uint8_t *name, uint16_t name_len,

                          uint16_t val_len, int type, AVDictionary **met)

{

    int ret;

    uint8_t *value;

    uint16_t buflen = 2 * val_len + 1;

    AVIOContext *pb = s->pb;



    value = av_malloc(buflen);

    if (!value)

        return AVERROR(ENOMEM);

    if (type == ASF_UNICODE) {

        // get_asf_string reads UTF-16 and converts it to UTF-8 which needs longer buffer

        if ((ret = get_asf_string(pb, val_len, value, buflen)) < 0)

            goto failed;

        if (av_dict_set(met, name, value, 0) < 0)

            av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");

    } else {

        char buf[256];

        if (val_len > sizeof(buf)) {

            ret = AVERROR_INVALIDDATA;

            goto failed;

        }

        if ((ret = avio_read(pb, value, val_len)) < 0)

            goto failed;

        if (ret < 2 * val_len)

            value[ret] = '\0';

        else

            value[2 * val_len - 1] = '\0';

        snprintf(buf, sizeof(buf), "%s", value);

        if (av_dict_set(met, name, buf, 0) < 0)

            av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");

    }

    av_freep(&value);



    return 0;



failed:

    av_freep(&value);

    return ret;

}

static int asf_read_value(AVFormatContext *s, uint8_t *name, uint16_t name_len,

                          uint16_t val_len, int type, AVDictionary **met)

{

    int ret;

    uint8_t *value;

    uint16_t buflen = 2 * val_len + 1;

    AVIOContext *pb = s->pb;



    value = av_malloc(buflen);

    if (!value)

        return AVERROR(ENOMEM);

    if (type == ASF_UNICODE) {

        

        if ((ret = get_asf_string(pb, val_len, value, buflen)) < 0)

            goto failed;

        if (av_dict_set(met, name, value, 0) < 0)

            av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");

    } else {

        char buf[256];

        if (val_len > sizeof(buf)) {

            ret = AVERROR_INVALIDDATA;

            goto failed;

        }

        if ((ret = avio_read(pb, value, val_len)) < 0)

            goto failed;

        if (ret < 2 * val_len)

            value[ret] = '\0';

        else

            value[2 * val_len - 1] = '\0';

        snprintf(buf, sizeof(buf), "%s", value);

        if (av_dict_set(met, name, buf, 0) < 0)

            av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");

    }

    av_freep(&value);



    return 0;



failed:

    av_freep(&value);

    return ret;

}

static int asf_read_value(AVFormatContext *s, uint8_t *name, uint16_t name_len,
static int FUNC_0(AVFormatContext *VAR_0, uint8_t *VAR_1, uint16_t VAR_2,

                          uint16_t VAR_3, int VAR_4, AVDictionary **VAR_5)

{

    int VAR_6;

    uint8_t *value;

    uint16_t buflen = 2 * VAR_3 + 1;

    AVIOContext *pb = VAR_0->pb;



    value = av_malloc(buflen);

    if (!value)

        return AVERROR(ENOMEM);

    if (VAR_4 == ASF_UNICODE) {

        

        if ((VAR_6 = get_asf_string(pb, VAR_3, value, buflen)) < 0)

            goto failed;

        if (av_dict_set(VAR_5, VAR_1, value, 0) < 0)

            av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n");

    } else {

        char VAR_7[256];

        if (VAR_3 > sizeof(VAR_7)) {

            VAR_6 = AVERROR_INVALIDDATA;

            goto failed;

        }

        if ((VAR_6 = avio_read(pb, value, VAR_3)) < 0)

            goto failed;

        if (VAR_6 < 2 * VAR_3)

            value[VAR_6] = '\0';

        else

            value[2 * VAR_3 - 1] = '\0';

        snprintf(VAR_7, sizeof(VAR_7), "%VAR_0", value);

        if (av_dict_set(VAR_5, VAR_1, VAR_7, 0) < 0)

            av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n");

    }

    av_freep(&value);



    return 0;



failed:

    av_freep(&value);

    return VAR_6;

}

static int FUNC_0(AVFormatContext *VAR_0, uint8_t *VAR_1, uint16_t VAR_2,
uint16_t VAR_3, int VAR_4, AVDictionary **VAR_5)
{ int VAR_6; uint8_t *value; uint16_t buflen = 2 * VAR_3 + 1; AVIOContext *pb = VAR_0->pb; value = av_malloc(buflen); if (!value)
return AVERROR(ENOMEM); if (VAR_4 == ASF_UNICODE) { if ((VAR_6 = get_asf_string(pb, VAR_3, value, buflen)) < 0)
goto failed; if (av_dict_set(VAR_5, VAR_1, value, 0) < 0)
av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n"); } else { char VAR_7[256]; if (VAR_3 > sizeof(VAR_7)) { VAR_6 = AVERROR_INVALIDDATA; goto failed; } if ((VAR_6 = avio_read(pb, value, VAR_3)) < 0)
goto failed; if (VAR_6 < 2 * VAR_3)
value[VAR_6] = '\0'; else
value[2 * VAR_3 - 1] = '\0'; snprintf(VAR_7, sizeof(VAR_7), "%VAR_0", value); if (av_dict_set(VAR_5, VAR_1, VAR_7, 0) < 0)
av_log(VAR_0, AV_LOG_WARNING, "av_dict_set failed.\n"); } av_freep(&value); return 0; failed:
av_freep(&value); return VAR_6; }