static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    int entries, i, j;



    if (c->fc->nb_streams < 1)

        return 0;

    st = c->fc->streams[c->fc->nb_streams-1];

    sc = st->priv_data;



    avio_rb32(pb); // version + flags

    entries = avio_rb32(pb);

    if (entries >  (atom.size - 1) / MIN_DATA_ENTRY_BOX_SIZE + 1 ||

        entries >= UINT_MAX / sizeof(*sc->drefs))

        return AVERROR_INVALIDDATA;

    av_free(sc->drefs);

    sc->drefs_count = 0;

    sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));

    if (!sc->drefs)

        return AVERROR(ENOMEM);

    sc->drefs_count = entries;



    for (i = 0; i < sc->drefs_count; i++) {

        MOVDref *dref = &sc->drefs[i];

        uint32_t size = avio_rb32(pb);

        int64_t next = avio_tell(pb) + size - 4;



        if (size < 12)

            return AVERROR_INVALIDDATA;



        dref->type = avio_rl32(pb);

        avio_rb32(pb); // version + flags

        av_dlog(c->fc, "type %.4s size %d\n", (char*)&dref->type, size);



        if (dref->type == MKTAG('a','l','i','s') && size > 150) {

            /* macintosh alias record */

            uint16_t volume_len, len;

            int16_t type;



            avio_skip(pb, 10);



            volume_len = avio_r8(pb);

            volume_len = FFMIN(volume_len, 27);

            avio_read(pb, dref->volume, 27);

            dref->volume[volume_len] = 0;

            av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);



            avio_skip(pb, 12);



            len = avio_r8(pb);

            len = FFMIN(len, 63);

            avio_read(pb, dref->filename, 63);

            dref->filename[len] = 0;

            av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);



            avio_skip(pb, 16);



            /* read next level up_from_alias/down_to_target */

            dref->nlvl_from = avio_rb16(pb);

            dref->nlvl_to   = avio_rb16(pb);

            av_log(c->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n",

                   dref->nlvl_from, dref->nlvl_to);



            avio_skip(pb, 16);



            for (type = 0; type != -1 && avio_tell(pb) < next; ) {

                if(url_feof(pb))

                    return AVERROR_EOF;

                type = avio_rb16(pb);

                len = avio_rb16(pb);

                av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);

                if (len&1)

                    len += 1;

                if (type == 2) { // absolute path

                    av_free(dref->path);

                    dref->path = av_mallocz(len+1);

                    if (!dref->path)

                        return AVERROR(ENOMEM);

                    avio_read(pb, dref->path, len);

                    if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) {

                        len -= volume_len;

                        memmove(dref->path, dref->path+volume_len, len);

                        dref->path[len] = 0;

                    }

                    for (j = 0; j < len; j++)

                        if (dref->path[j] == ':')

                            dref->path[j] = '/';

                    av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path);

                } else if (type == 0) { // directory name

                    av_free(dref->dir);

                    dref->dir = av_malloc(len+1);

                    if (!dref->dir)

                        return AVERROR(ENOMEM);

                    avio_read(pb, dref->dir, len);

                    dref->dir[len] = 0;

                    for (j = 0; j < len; j++)

                        if (dref->dir[j] == ':')

                            dref->dir[j] = '/';

                    av_log(c->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir);

                } else

                    avio_skip(pb, len);

            }

        }

        avio_seek(pb, next, SEEK_SET);

    }

    return 0;

}

static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)

{

    AVStream *st;

    MOVStreamContext *sc;

    int entries, i, j;



    if (c->fc->nb_streams < 1)

        return 0;

    st = c->fc->streams[c->fc->nb_streams-1];

    sc = st->priv_data;



    avio_rb32(pb); 

    entries = avio_rb32(pb);

    if (entries >  (atom.size - 1) / MIN_DATA_ENTRY_BOX_SIZE + 1 ||

        entries >= UINT_MAX / sizeof(*sc->drefs))

        return AVERROR_INVALIDDATA;

    av_free(sc->drefs);

    sc->drefs_count = 0;

    sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));

    if (!sc->drefs)

        return AVERROR(ENOMEM);

    sc->drefs_count = entries;



    for (i = 0; i < sc->drefs_count; i++) {

        MOVDref *dref = &sc->drefs[i];

        uint32_t size = avio_rb32(pb);

        int64_t next = avio_tell(pb) + size - 4;



        if (size < 12)

            return AVERROR_INVALIDDATA;



        dref->type = avio_rl32(pb);

        avio_rb32(pb); 

        av_dlog(c->fc, "type %.4s size %d\n", (char*)&dref->type, size);



        if (dref->type == MKTAG('a','l','i','s') && size > 150) {

            

            uint16_t volume_len, len;

            int16_t type;



            avio_skip(pb, 10);



            volume_len = avio_r8(pb);

            volume_len = FFMIN(volume_len, 27);

            avio_read(pb, dref->volume, 27);

            dref->volume[volume_len] = 0;

            av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);



            avio_skip(pb, 12);



            len = avio_r8(pb);

            len = FFMIN(len, 63);

            avio_read(pb, dref->filename, 63);

            dref->filename[len] = 0;

            av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);



            avio_skip(pb, 16);



            

            dref->nlvl_from = avio_rb16(pb);

            dref->nlvl_to   = avio_rb16(pb);

            av_log(c->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n",

                   dref->nlvl_from, dref->nlvl_to);



            avio_skip(pb, 16);



            for (type = 0; type != -1 && avio_tell(pb) < next; ) {

                if(url_feof(pb))

                    return AVERROR_EOF;

                type = avio_rb16(pb);

                len = avio_rb16(pb);

                av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);

                if (len&1)

                    len += 1;

                if (type == 2) { 

                    av_free(dref->path);

                    dref->path = av_mallocz(len+1);

                    if (!dref->path)

                        return AVERROR(ENOMEM);

                    avio_read(pb, dref->path, len);

                    if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) {

                        len -= volume_len;

                        memmove(dref->path, dref->path+volume_len, len);

                        dref->path[len] = 0;

                    }

                    for (j = 0; j < len; j++)

                        if (dref->path[j] == ':')

                            dref->path[j] = '/';

                    av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path);

                } else if (type == 0) { 

                    av_free(dref->dir);

                    dref->dir = av_malloc(len+1);

                    if (!dref->dir)

                        return AVERROR(ENOMEM);

                    avio_read(pb, dref->dir, len);

                    dref->dir[len] = 0;

                    for (j = 0; j < len; j++)

                        if (dref->dir[j] == ':')

                            dref->dir[j] = '/';

                    av_log(c->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir);

                } else

                    avio_skip(pb, len);

            }

        }

        avio_seek(pb, next, SEEK_SET);

    }

    return 0;

}

                    avio_read(pb, dref->dir, len);
static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)

{

    AVStream *st;

    MOVStreamContext *sc;

    int VAR_3, VAR_4, VAR_5;



    if (VAR_0->fc->nb_streams < 1)

        return 0;

    st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1];

    sc = st->priv_data;



    avio_rb32(VAR_1); 

    VAR_3 = avio_rb32(VAR_1);

    if (VAR_3 >  (VAR_2.size - 1) / MIN_DATA_ENTRY_BOX_SIZE + 1 ||

        VAR_3 >= UINT_MAX / sizeof(*sc->drefs))

        return AVERROR_INVALIDDATA;

    av_free(sc->drefs);

    sc->drefs_count = 0;

    sc->drefs = av_mallocz(VAR_3 * sizeof(*sc->drefs));

    if (!sc->drefs)

        return AVERROR(ENOMEM);

    sc->drefs_count = VAR_3;



    for (VAR_4 = 0; VAR_4 < sc->drefs_count; VAR_4++) {

        MOVDref *dref = &sc->drefs[VAR_4];

        uint32_t size = avio_rb32(VAR_1);

        int64_t next = avio_tell(VAR_1) + size - 4;



        if (size < 12)

            return AVERROR_INVALIDDATA;



        dref->type = avio_rl32(VAR_1);

        avio_rb32(VAR_1); 

        av_dlog(VAR_0->fc, "type %.4s size %d\n", (char*)&dref->type, size);



        if (dref->type == MKTAG('a','l','VAR_4','s') && size > 150) {

            

            uint16_t volume_len, len;

            int16_t type;



            avio_skip(VAR_1, 10);



            volume_len = avio_r8(VAR_1);

            volume_len = FFMIN(volume_len, 27);

            avio_read(VAR_1, dref->volume, 27);

            dref->volume[volume_len] = 0;

            av_log(VAR_0->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);



            avio_skip(VAR_1, 12);



            len = avio_r8(VAR_1);

            len = FFMIN(len, 63);

            avio_read(VAR_1, dref->filename, 63);

            dref->filename[len] = 0;

            av_log(VAR_0->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);



            avio_skip(VAR_1, 16);



            

            dref->nlvl_from = avio_rb16(VAR_1);

            dref->nlvl_to   = avio_rb16(VAR_1);

            av_log(VAR_0->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n",

                   dref->nlvl_from, dref->nlvl_to);



            avio_skip(VAR_1, 16);



            for (type = 0; type != -1 && avio_tell(VAR_1) < next; ) {

                if(url_feof(VAR_1))

                    return AVERROR_EOF;

                type = avio_rb16(VAR_1);

                len = avio_rb16(VAR_1);

                av_log(VAR_0->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);

                if (len&1)

                    len += 1;

                if (type == 2) { 

                    av_free(dref->path);

                    dref->path = av_mallocz(len+1);

                    if (!dref->path)

                        return AVERROR(ENOMEM);

                    avio_read(VAR_1, dref->path, len);

                    if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) {

                        len -= volume_len;

                        memmove(dref->path, dref->path+volume_len, len);

                        dref->path[len] = 0;

                    }

                    for (VAR_5 = 0; VAR_5 < len; VAR_5++)

                        if (dref->path[VAR_5] == ':')

                            dref->path[VAR_5] = '/';

                    av_log(VAR_0->fc, AV_LOG_DEBUG, "path %s\n", dref->path);

                } else if (type == 0) { 

                    av_free(dref->dir);

                    dref->dir = av_malloc(len+1);

                    if (!dref->dir)

                        return AVERROR(ENOMEM);

                    avio_read(VAR_1, dref->dir, len);

                    dref->dir[len] = 0;

                    for (VAR_5 = 0; VAR_5 < len; VAR_5++)

                        if (dref->dir[VAR_5] == ':')

                            dref->dir[VAR_5] = '/';

                    av_log(VAR_0->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir);

                } else

                    avio_skip(VAR_1, len);

            }

        }

        avio_seek(VAR_1, next, SEEK_SET);

    }

    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)
{ AVStream *st; MOVStreamContext *sc; int VAR_3, VAR_4, VAR_5; if (VAR_0->fc->nb_streams < 1)
return 0; st = VAR_0->fc->streams[VAR_0->fc->nb_streams-1]; sc = st->priv_data; avio_rb32(VAR_1); VAR_3 = avio_rb32(VAR_1); if (VAR_3 >  (VAR_2.size - 1) / MIN_DATA_ENTRY_BOX_SIZE + 1 ||
VAR_3 >= UINT_MAX / sizeof(*sc->drefs))
return AVERROR_INVALIDDATA; av_free(sc->drefs); sc->drefs_count = 0; sc->drefs = av_mallocz(VAR_3 * sizeof(*sc->drefs)); if (!sc->drefs)
return AVERROR(ENOMEM); sc->drefs_count = VAR_3; for (VAR_4 = 0; VAR_4 < sc->drefs_count; VAR_4++) { MOVDref *dref = &sc->drefs[VAR_4]; uint32_t size = avio_rb32(VAR_1); int64_t next = avio_tell(VAR_1) + size - 4; if (size < 12)
return AVERROR_INVALIDDATA; dref->type = avio_rl32(VAR_1); avio_rb32(VAR_1); av_dlog(VAR_0->fc, "type %.4s size %d\n", (char*)&dref->type, size); if (dref->type == MKTAG('a','l','VAR_4','s') && size > 150) { uint16_t volume_len, len; int16_t type; avio_skip(VAR_1, 10); volume_len = avio_r8(VAR_1); volume_len = FFMIN(volume_len, 27); avio_read(VAR_1, dref->volume, 27); dref->volume[volume_len] = 0; av_log(VAR_0->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len); avio_skip(VAR_1, 12); len = avio_r8(VAR_1); len = FFMIN(len, 63); avio_read(VAR_1, dref->filename, 63); dref->filename[len] = 0; av_log(VAR_0->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len); avio_skip(VAR_1, 16); dref->nlvl_from = avio_rb16(VAR_1); dref->nlvl_to   = avio_rb16(VAR_1); av_log(VAR_0->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n",
dref->nlvl_from, dref->nlvl_to); avio_skip(VAR_1, 16); for (type = 0; type != -1 && avio_tell(VAR_1) < next; ) { if(url_feof(VAR_1))
return AVERROR_EOF; type = avio_rb16(VAR_1); len = avio_rb16(VAR_1); av_log(VAR_0->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len); if (len&1)
len += 1; if (type == 2) { av_free(dref->path); dref->path = av_mallocz(len+1); if (!dref->path)
return AVERROR(ENOMEM); avio_read(VAR_1, dref->path, len); if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) { len -= volume_len; memmove(dref->path, dref->path+volume_len, len); dref->path[len] = 0; } for (VAR_5 = 0; VAR_5 < len; VAR_5++) if (dref->path[VAR_5] == ':')
dref->path[VAR_5] = '/'; av_log(VAR_0->fc, AV_LOG_DEBUG, "path %s\n", dref->path); } else if (type == 0) { av_free(dref->dir); dref->dir = av_malloc(len+1); if (!dref->dir)
return AVERROR(ENOMEM); avio_read(VAR_1, dref->dir, len); dref->dir[len] = 0; for (VAR_5 = 0; VAR_5 < len; VAR_5++) if (dref->dir[VAR_5] == ':')
dref->dir[VAR_5] = '/'; av_log(VAR_0->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir); } else avio_skip(VAR_1, len); } } avio_seek(VAR_1, next, SEEK_SET); } return 0; }