static int gif_read_extension(GifState *s)

{

    int ext_code, ext_len, gce_flags, gce_transparent_index;



    /* There must be at least 2 bytes:

     * 1 for extension label and 1 for extension length. */

    if (bytestream2_get_bytes_left(&s->gb) < 2)

        return AVERROR_INVALIDDATA;



    ext_code = bytestream2_get_byteu(&s->gb);

    ext_len = bytestream2_get_byteu(&s->gb);



    av_dlog(s->avctx, "ext_code=0x%x len=%d\n", ext_code, ext_len);



    switch(ext_code) {

    case GIF_GCE_EXT_LABEL:

        if (ext_len != 4)

            goto discard_ext;



        /* We need at least 5 bytes more: 4 is for extension body

         * and 1 for next block size. */

        if (bytestream2_get_bytes_left(&s->gb) < 5)

            return AVERROR_INVALIDDATA;



        gce_flags = bytestream2_get_byteu(&s->gb);

        bytestream2_skipu(&s->gb, 2);    // delay during which the frame is shown

        gce_transparent_index = bytestream2_get_byteu(&s->gb);

        if (gce_flags & 0x01)

            s->transparent_color_index = gce_transparent_index;

        else

            s->transparent_color_index = -1;

        s->gce_disposal = (gce_flags >> 2) & 0x7;



        av_dlog(s->avctx, "gce_flags=%x tcolor=%d disposal=%d\n",

               gce_flags,

               s->transparent_color_index, s->gce_disposal);



        if (s->gce_disposal > 3) {

            s->gce_disposal = GCE_DISPOSAL_NONE;

            av_dlog(s->avctx, "invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);

        }



        ext_len = bytestream2_get_byteu(&s->gb);

        break;

    }



    /* NOTE: many extension blocks can come after */

 discard_ext:

    while (ext_len != 0) {

        /* There must be at least ext_len bytes and 1 for next block size byte. */

        if (bytestream2_get_bytes_left(&s->gb) < ext_len + 1)

            return AVERROR_INVALIDDATA;



        bytestream2_skipu(&s->gb, ext_len);

        ext_len = bytestream2_get_byteu(&s->gb);



        av_dlog(s->avctx, "ext_len1=%d\n", ext_len);

    }

    return 0;

}

static int gif_read_extension(GifState *s)

{

    int ext_code, ext_len, gce_flags, gce_transparent_index;



    



    if (bytestream2_get_bytes_left(&s->gb) < 2)

        return AVERROR_INVALIDDATA;



    ext_code = bytestream2_get_byteu(&s->gb);

    ext_len = bytestream2_get_byteu(&s->gb);



    av_dlog(s->avctx, "ext_code=0x%x len=%d\n", ext_code, ext_len);



    switch(ext_code) {

    case GIF_GCE_EXT_LABEL:

        if (ext_len != 4)

            goto discard_ext;



        



        if (bytestream2_get_bytes_left(&s->gb) < 5)

            return AVERROR_INVALIDDATA;



        gce_flags = bytestream2_get_byteu(&s->gb);

        bytestream2_skipu(&s->gb, 2);    

        gce_transparent_index = bytestream2_get_byteu(&s->gb);

        if (gce_flags & 0x01)

            s->transparent_color_index = gce_transparent_index;

        else

            s->transparent_color_index = -1;

        s->gce_disposal = (gce_flags >> 2) & 0x7;



        av_dlog(s->avctx, "gce_flags=%x tcolor=%d disposal=%d\n",

               gce_flags,

               s->transparent_color_index, s->gce_disposal);



        if (s->gce_disposal > 3) {

            s->gce_disposal = GCE_DISPOSAL_NONE;

            av_dlog(s->avctx, "invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);

        }



        ext_len = bytestream2_get_byteu(&s->gb);

        break;

    }



    

 discard_ext:

    while (ext_len != 0) {

        

        if (bytestream2_get_bytes_left(&s->gb) < ext_len + 1)

            return AVERROR_INVALIDDATA;



        bytestream2_skipu(&s->gb, ext_len);

        ext_len = bytestream2_get_byteu(&s->gb);



        av_dlog(s->avctx, "ext_len1=%d\n", ext_len);

    }

    return 0;

}

static int FUNC_0(GifState *VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4;



    



    if (bytestream2_get_bytes_left(&VAR_0->gb) < 2)

        return AVERROR_INVALIDDATA;



    VAR_1 = bytestream2_get_byteu(&VAR_0->gb);

    VAR_2 = bytestream2_get_byteu(&VAR_0->gb);



    av_dlog(VAR_0->avctx, "VAR_1=0x%x len=%d\n", VAR_1, VAR_2);



    switch(VAR_1) {

    case GIF_GCE_EXT_LABEL:

        if (VAR_2 != 4)

            goto discard_ext;



        



        if (bytestream2_get_bytes_left(&VAR_0->gb) < 5)

            return AVERROR_INVALIDDATA;



        VAR_3 = bytestream2_get_byteu(&VAR_0->gb);

        bytestream2_skipu(&VAR_0->gb, 2);    

        VAR_4 = bytestream2_get_byteu(&VAR_0->gb);

        if (VAR_3 & 0x01)

            VAR_0->transparent_color_index = VAR_4;

        else

            VAR_0->transparent_color_index = -1;

        VAR_0->gce_disposal = (VAR_3 >> 2) & 0x7;



        av_dlog(VAR_0->avctx, "VAR_3=%x tcolor=%d disposal=%d\n",

               VAR_3,

               VAR_0->transparent_color_index, VAR_0->gce_disposal);



        if (VAR_0->gce_disposal > 3) {

            VAR_0->gce_disposal = GCE_DISPOSAL_NONE;

            av_dlog(VAR_0->avctx, "invalid value in gce_disposal (%d). Using default value of 0.\n", VAR_2);

        }



        VAR_2 = bytestream2_get_byteu(&VAR_0->gb);

        break;

    }



    

 discard_ext:

    while (VAR_2 != 0) {

        

        if (bytestream2_get_bytes_left(&VAR_0->gb) < VAR_2 + 1)

            return AVERROR_INVALIDDATA;



        bytestream2_skipu(&VAR_0->gb, VAR_2);

        VAR_2 = bytestream2_get_byteu(&VAR_0->gb);



        av_dlog(VAR_0->avctx, "ext_len1=%d\n", VAR_2);

    }

    return 0;

}

static int FUNC_0(GifState *VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4; if (bytestream2_get_bytes_left(&VAR_0->gb) < 2)
return AVERROR_INVALIDDATA; VAR_1 = bytestream2_get_byteu(&VAR_0->gb); VAR_2 = bytestream2_get_byteu(&VAR_0->gb); av_dlog(VAR_0->avctx, "VAR_1=0x%x len=%d\n", VAR_1, VAR_2); switch(VAR_1) { case GIF_GCE_EXT_LABEL:
if (VAR_2 != 4)
goto discard_ext; if (bytestream2_get_bytes_left(&VAR_0->gb) < 5)
return AVERROR_INVALIDDATA; VAR_3 = bytestream2_get_byteu(&VAR_0->gb); bytestream2_skipu(&VAR_0->gb, 2); VAR_4 = bytestream2_get_byteu(&VAR_0->gb); if (VAR_3 & 0x01)
VAR_0->transparent_color_index = VAR_4; else
VAR_0->transparent_color_index = -1; VAR_0->gce_disposal = (VAR_3 >> 2) & 0x7; av_dlog(VAR_0->avctx, "VAR_3=%x tcolor=%d disposal=%d\n",
VAR_3,
VAR_0->transparent_color_index, VAR_0->gce_disposal); if (VAR_0->gce_disposal > 3) { VAR_0->gce_disposal = GCE_DISPOSAL_NONE; av_dlog(VAR_0->avctx, "invalid value in gce_disposal (%d). Using default value of 0.\n", VAR_2); } VAR_2 = bytestream2_get_byteu(&VAR_0->gb); break; } discard_ext:
while (VAR_2 != 0) { if (bytestream2_get_bytes_left(&VAR_0->gb) < VAR_2 + 1)
return AVERROR_INVALIDDATA; bytestream2_skipu(&VAR_0->gb, VAR_2); VAR_2 = bytestream2_get_byteu(&VAR_0->gb); av_dlog(VAR_0->avctx, "ext_len1=%d\n", VAR_2); } return 0; }