static int decode_bdlt(uint8_t *frame, int width, int height,

                       const uint8_t *src, const uint8_t *src_end)

{

    const uint8_t *frame_end = frame + width * height;

    uint8_t *line_ptr;

    int count, lines, segments;



    count = bytestream_get_le16(&src);

    if (count >= height || width * count < 0)

        return -1;

    frame += width * count;

    lines = bytestream_get_le16(&src);

    if (frame + lines * width > frame_end || src >= src_end)

        return -1;



    while (lines--) {

        line_ptr = frame;

        frame += width;

        segments = *src++;

        while (segments--) {

            if (src_end - src < 3)

                return -1;

            line_ptr += *src++;

            if (line_ptr >= frame)

                return -1;

            count = (int8_t)*src++;

            if (count >= 0) {

                if (line_ptr + count > frame || src_end - src < count)

                    return -1;

                bytestream_get_buffer(&src, line_ptr, count);

            } else {

                count = -count;

                if (line_ptr + count > frame || src >= src_end)

                    return -1;

                memset(line_ptr, *src++, count);

            }

            line_ptr += count;

        }

    }



    return 0;

}

static int decode_bdlt(uint8_t *frame, int width, int height,

                       const uint8_t *src, const uint8_t *src_end)

{

    const uint8_t *frame_end = frame + width * height;

    uint8_t *line_ptr;

    int count, lines, segments;



    count = bytestream_get_le16(&src);

    if (count >= height || width * count < 0)

        return -1;

    frame += width * count;

    lines = bytestream_get_le16(&src);

    if (frame + lines * width > frame_end || src >= src_end)

        return -1;



    while (lines--) {

        line_ptr = frame;

        frame += width;

        segments = *src++;

        while (segments--) {

            if (src_end - src < 3)

                return -1;

            line_ptr += *src++;

            if (line_ptr >= frame)

                return -1;

            count = (int8_t)*src++;

            if (count >= 0) {

                if (line_ptr + count > frame || src_end - src < count)

                    return -1;

                bytestream_get_buffer(&src, line_ptr, count);

            } else {

                count = -count;

                if (line_ptr + count > frame || src >= src_end)

                    return -1;

                memset(line_ptr, *src++, count);

            }

            line_ptr += count;

        }

    }



    return 0;

}

    if (count >= height || width * count < 0)     if (frame + lines * width > frame_end || src >= src_end)             line_ptr += *src++;             if (line_ptr >= frame)                 if (line_ptr + count > frame || src_end - src < count)                 if (line_ptr + count > frame || src >= src_end)     if (frame + lines * width > frame_end || src >= src_end)             line_ptr += *src++;             if (line_ptr >= frame)
static int FUNC_0(uint8_t *VAR_0, int VAR_1, int VAR_2,

                       const uint8_t *VAR_3, const uint8_t *VAR_4)

{

    const uint8_t *VAR_5 = VAR_0 + VAR_1 * VAR_2;

    uint8_t *line_ptr;

    int VAR_6, VAR_7, VAR_8;



    VAR_6 = bytestream_get_le16(&VAR_3);

    if (VAR_6 >= VAR_2 || VAR_1 * VAR_6 < 0)

        return -1;

    VAR_0 += VAR_1 * VAR_6;

    VAR_7 = bytestream_get_le16(&VAR_3);

    if (VAR_0 + VAR_7 * VAR_1 > VAR_5 || VAR_3 >= VAR_4)

        return -1;



    while (VAR_7--) {

        line_ptr = VAR_0;

        VAR_0 += VAR_1;

        VAR_8 = *VAR_3++;

        while (VAR_8--) {

            if (VAR_4 - VAR_3 < 3)

                return -1;

            line_ptr += *VAR_3++;

            if (line_ptr >= VAR_0)

                return -1;

            VAR_6 = (int8_t)*VAR_3++;

            if (VAR_6 >= 0) {

                if (line_ptr + VAR_6 > VAR_0 || VAR_4 - VAR_3 < VAR_6)

                    return -1;

                bytestream_get_buffer(&VAR_3, line_ptr, VAR_6);

            } else {

                VAR_6 = -VAR_6;

                if (line_ptr + VAR_6 > VAR_0 || VAR_3 >= VAR_4)

                    return -1;

                memset(line_ptr, *VAR_3++, VAR_6);

            }

            line_ptr += VAR_6;

        }

    }



    return 0;

}

static int FUNC_0(uint8_t *VAR_0, int VAR_1, int VAR_2,
const uint8_t *VAR_3, const uint8_t *VAR_4)
{ const uint8_t *VAR_5 = VAR_0 + VAR_1 * VAR_2; uint8_t *line_ptr; int VAR_6, VAR_7, VAR_8; VAR_6 = bytestream_get_le16(&VAR_3); if (VAR_6 >= VAR_2 || VAR_1 * VAR_6 < 0)
return -1; VAR_0 += VAR_1 * VAR_6; VAR_7 = bytestream_get_le16(&VAR_3); if (VAR_0 + VAR_7 * VAR_1 > VAR_5 || VAR_3 >= VAR_4)
return -1; while (VAR_7--) { line_ptr = VAR_0; VAR_0 += VAR_1; VAR_8 = *VAR_3++; while (VAR_8--) { if (VAR_4 - VAR_3 < 3)
return -1; line_ptr += *VAR_3++; if (line_ptr >= VAR_0)
return -1; VAR_6 = (int8_t)*VAR_3++; if (VAR_6 >= 0) { if (line_ptr + VAR_6 > VAR_0 || VAR_4 - VAR_3 < VAR_6)
return -1; bytestream_get_buffer(&VAR_3, line_ptr, VAR_6); } else { VAR_6 = -VAR_6; if (line_ptr + VAR_6 > VAR_0 || VAR_3 >= VAR_4)
return -1; memset(line_ptr, *VAR_3++, VAR_6); } line_ptr += VAR_6; } } return 0; }