static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf,

                        const uint8_t *in_end, SgiState* s)

{

    uint8_t *dest_row;

    unsigned int len = s->height * s->depth * 4;

    const uint8_t *start_table = in_buf;

    unsigned int y, z;

    unsigned int start_offset;



    /* size of  RLE offset and length tables */

    if(len * 2  > in_end - in_buf) {

        return AVERROR_INVALIDDATA;

    }



    in_buf -= SGI_HEADER_SIZE;

    for (z = 0; z < s->depth; z++) {

        dest_row = out_buf;

        for (y = 0; y < s->height; y++) {

            dest_row -= s->linesize;

            start_offset = bytestream_get_be32(&start_table);

            if(start_offset > in_end - in_buf) {

                return AVERROR_INVALIDDATA;

            }

            if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z,

                dest_row + FFABS(s->linesize), s->depth) != s->width)

                return AVERROR_INVALIDDATA;

        }

    }

    return 0;

}

static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf,

                        const uint8_t *in_end, SgiState* s)

{

    uint8_t *dest_row;

    unsigned int len = s->height * s->depth * 4;

    const uint8_t *start_table = in_buf;

    unsigned int y, z;

    unsigned int start_offset;



    

    if(len * 2  > in_end - in_buf) {

        return AVERROR_INVALIDDATA;

    }



    in_buf -= SGI_HEADER_SIZE;

    for (z = 0; z < s->depth; z++) {

        dest_row = out_buf;

        for (y = 0; y < s->height; y++) {

            dest_row -= s->linesize;

            start_offset = bytestream_get_be32(&start_table);

            if(start_offset > in_end - in_buf) {

                return AVERROR_INVALIDDATA;

            }

            if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z,

                dest_row + FFABS(s->linesize), s->depth) != s->width)

                return AVERROR_INVALIDDATA;

        }

    }

    return 0;

}

static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf,                         const uint8_t *in_end, SgiState* s)     const uint8_t *start_table = in_buf;     if(len * 2  > in_end - in_buf) {     in_buf -= SGI_HEADER_SIZE;             start_offset = bytestream_get_be32(&start_table);             if(start_offset > in_end - in_buf) {             if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z,                 dest_row + FFABS(s->linesize), s->depth) != s->width)                 return AVERROR_INVALIDDATA;
static int FUNC_0(unsigned char* VAR_0, const uint8_t *VAR_1,

                        const uint8_t *VAR_2, SgiState* VAR_3)

{

    uint8_t *dest_row;

    unsigned int VAR_4 = VAR_3->height * VAR_3->depth * 4;

    const uint8_t *VAR_5 = VAR_1;

    unsigned int VAR_6, VAR_7;

    unsigned int VAR_8;



    

    if(VAR_4 * 2  > VAR_2 - VAR_1) {

        return AVERROR_INVALIDDATA;

    }



    VAR_1 -= SGI_HEADER_SIZE;

    for (VAR_7 = 0; VAR_7 < VAR_3->depth; VAR_7++) {

        dest_row = VAR_0;

        for (VAR_6 = 0; VAR_6 < VAR_3->height; VAR_6++) {

            dest_row -= VAR_3->linesize;

            VAR_8 = bytestream_get_be32(&VAR_5);

            if(VAR_8 > VAR_2 - VAR_1) {

                return AVERROR_INVALIDDATA;

            }

            if (expand_rle_row(VAR_1 + VAR_8, VAR_2, dest_row + VAR_7,

                dest_row + FFABS(VAR_3->linesize), VAR_3->depth) != VAR_3->width)

                return AVERROR_INVALIDDATA;

        }

    }

    return 0;

}

static int FUNC_0(unsigned char* VAR_0, const uint8_t *VAR_1,
const uint8_t *VAR_2, SgiState* VAR_3)
{ uint8_t *dest_row; unsigned int VAR_4 = VAR_3->height * VAR_3->depth * 4; const uint8_t *VAR_5 = VAR_1; unsigned int VAR_6, VAR_7; unsigned int VAR_8; if(VAR_4 * 2  > VAR_2 - VAR_1) { return AVERROR_INVALIDDATA; } VAR_1 -= SGI_HEADER_SIZE; for (VAR_7 = 0; VAR_7 < VAR_3->depth; VAR_7++) { dest_row = VAR_0; for (VAR_6 = 0; VAR_6 < VAR_3->height; VAR_6++) { dest_row -= VAR_3->linesize; VAR_8 = bytestream_get_be32(&VAR_5); if(VAR_8 > VAR_2 - VAR_1) { return AVERROR_INVALIDDATA; } if (expand_rle_row(VAR_1 + VAR_8, VAR_2, dest_row + VAR_7,
dest_row + FFABS(VAR_3->linesize), VAR_3->depth) != VAR_3->width)
return AVERROR_INVALIDDATA; } } return 0; }