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

{

    AVStream *st;

    MOVStreamContext *sc;

    unsigned int i, entries;



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

        return 0;

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

    sc = st->priv_data;



    avio_r8(pb); /* version */

    avio_rb24(pb); /* flags */



    entries = avio_rb32(pb);



    av_log(c->fc, AV_LOG_TRACE, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);



    if (!entries)

        return 0;

    if (entries >= UINT_MAX / sizeof(*sc->stsc_data))

        return AVERROR_INVALIDDATA;

    sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data));

    if (!sc->stsc_data)

        return AVERROR(ENOMEM);



    for (i = 0; i < entries && !pb->eof_reached; i++) {

        sc->stsc_data[i].first = avio_rb32(pb);

        sc->stsc_data[i].count = avio_rb32(pb);

        sc->stsc_data[i].id = avio_rb32(pb);

        if (sc->stsc_data[i].id < 0 || sc->stsc_data[i].id > sc->stsd_count) {

            sc->stsc_data[i].id = 0;

            if (c->fc->error_recognition & AV_EF_EXPLODE) {

                av_log(c->fc, AV_LOG_ERROR, "Invalid stsc index.\n");

                return AVERROR_INVALIDDATA;

            }

        }

    }



    sc->stsc_count = i;



    if (pb->eof_reached)

        return AVERROR_EOF;



    return 0;

}

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

{

    AVStream *st;

    MOVStreamContext *sc;

    unsigned int i, entries;



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

        return 0;

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

    sc = st->priv_data;



    avio_r8(pb); 

    avio_rb24(pb); 



    entries = avio_rb32(pb);



    av_log(c->fc, AV_LOG_TRACE, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);



    if (!entries)

        return 0;

    if (entries >= UINT_MAX / sizeof(*sc->stsc_data))

        return AVERROR_INVALIDDATA;

    sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data));

    if (!sc->stsc_data)

        return AVERROR(ENOMEM);



    for (i = 0; i < entries && !pb->eof_reached; i++) {

        sc->stsc_data[i].first = avio_rb32(pb);

        sc->stsc_data[i].count = avio_rb32(pb);

        sc->stsc_data[i].id = avio_rb32(pb);

        if (sc->stsc_data[i].id < 0 || sc->stsc_data[i].id > sc->stsd_count) {

            sc->stsc_data[i].id = 0;

            if (c->fc->error_recognition & AV_EF_EXPLODE) {

                av_log(c->fc, AV_LOG_ERROR, "Invalid stsc index.\n");

                return AVERROR_INVALIDDATA;

            }

        }

    }



    sc->stsc_count = i;



    if (pb->eof_reached)

        return AVERROR_EOF;



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)

{

    AVStream *st;

    MOVStreamContext *sc;

    unsigned int VAR_3, VAR_4;



    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_r8(VAR_1); 

    avio_rb24(VAR_1); 



    VAR_4 = avio_rb32(VAR_1);



    av_log(VAR_0->fc, AV_LOG_TRACE, "track[%VAR_3].stsc.VAR_4 = %VAR_3\n", VAR_0->fc->nb_streams-1, VAR_4);



    if (!VAR_4)

        return 0;

    if (VAR_4 >= UINT_MAX / sizeof(*sc->stsc_data))

        return AVERROR_INVALIDDATA;

    sc->stsc_data = av_malloc(VAR_4 * sizeof(*sc->stsc_data));

    if (!sc->stsc_data)

        return AVERROR(ENOMEM);



    for (VAR_3 = 0; VAR_3 < VAR_4 && !VAR_1->eof_reached; VAR_3++) {

        sc->stsc_data[VAR_3].first = avio_rb32(VAR_1);

        sc->stsc_data[VAR_3].count = avio_rb32(VAR_1);

        sc->stsc_data[VAR_3].id = avio_rb32(VAR_1);

        if (sc->stsc_data[VAR_3].id < 0 || sc->stsc_data[VAR_3].id > sc->stsd_count) {

            sc->stsc_data[VAR_3].id = 0;

            if (VAR_0->fc->error_recognition & AV_EF_EXPLODE) {

                av_log(VAR_0->fc, AV_LOG_ERROR, "Invalid stsc index.\n");

                return AVERROR_INVALIDDATA;

            }

        }

    }



    sc->stsc_count = VAR_3;



    if (VAR_1->eof_reached)

        return AVERROR_EOF;



    return 0;

}

static int FUNC_0(MOVContext *VAR_0, AVIOContext *VAR_1, MOVAtom VAR_2)
{ AVStream *st; MOVStreamContext *sc; unsigned int VAR_3, VAR_4; 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_r8(VAR_1); avio_rb24(VAR_1); VAR_4 = avio_rb32(VAR_1); av_log(VAR_0->fc, AV_LOG_TRACE, "track[%VAR_3].stsc.VAR_4 = %VAR_3\n", VAR_0->fc->nb_streams-1, VAR_4); if (!VAR_4)
return 0; if (VAR_4 >= UINT_MAX / sizeof(*sc->stsc_data))
return AVERROR_INVALIDDATA; sc->stsc_data = av_malloc(VAR_4 * sizeof(*sc->stsc_data)); if (!sc->stsc_data)
return AVERROR(ENOMEM); for (VAR_3 = 0; VAR_3 < VAR_4 && !VAR_1->eof_reached; VAR_3++) { sc->stsc_data[VAR_3].first = avio_rb32(VAR_1); sc->stsc_data[VAR_3].count = avio_rb32(VAR_1); sc->stsc_data[VAR_3].id = avio_rb32(VAR_1); if (sc->stsc_data[VAR_3].id < 0 || sc->stsc_data[VAR_3].id > sc->stsd_count) { sc->stsc_data[VAR_3].id = 0; if (VAR_0->fc->error_recognition & AV_EF_EXPLODE) { av_log(VAR_0->fc, AV_LOG_ERROR, "Invalid stsc index.\n"); return AVERROR_INVALIDDATA; } } } sc->stsc_count = VAR_3; if (VAR_1->eof_reached)
return AVERROR_EOF; return 0; }