static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,

                             const uint8_t *src, int size, int lines)

{

    int c, line, pixels, code, ret;

    const uint8_t *ssrc = src;

    int width           = ((s->width * s->bpp) + 7) >> 3;



    if (size <= 0)

        return AVERROR_INVALIDDATA;



    if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {

#if CONFIG_ZLIB

        return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);

#else

        av_log(s->avctx, AV_LOG_ERROR,

               "zlib support not enabled, "

               "deflate compression not supported\n");

        return AVERROR(ENOSYS);

#endif

    }

    if (s->compr == TIFF_LZW) {

        if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");

            return ret;

        }

    }

    if (s->compr == TIFF_CCITT_RLE ||

        s->compr == TIFF_G3        ||

        s->compr == TIFF_G4) {

        return tiff_unpack_fax(s, dst, stride, src, size, lines);

    }

    for (line = 0; line < lines; line++) {

        if (src - ssrc > size) {

            av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");

            return AVERROR_INVALIDDATA;

        }

        switch (s->compr) {

        case TIFF_RAW:

            if (ssrc + size - src < width)

                return AVERROR_INVALIDDATA;

            if (!s->fill_order) {

                memcpy(dst, src, width);

            } else {

                int i;

                for (i = 0; i < width; i++)

                    dst[i] = ff_reverse[src[i]];

            }

            src += width;

            break;

        case TIFF_PACKBITS:

            for (pixels = 0; pixels < width;) {

                code = (int8_t) *src++;

                if (code >= 0) {

                    code++;

                    if (pixels + code > width) {

                        av_log(s->avctx, AV_LOG_ERROR,

                               "Copy went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    memcpy(dst + pixels, src, code);

                    src    += code;

                    pixels += code;

                } else if (code != -128) { // -127..-1

                    code = (-code) + 1;

                    if (pixels + code > width) {

                        av_log(s->avctx, AV_LOG_ERROR,

                               "Run went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    c = *src++;

                    memset(dst + pixels, c, code);

                    pixels += code;

                }

            }

            break;

        case TIFF_LZW:

            pixels = ff_lzw_decode(s->lzw, dst, width);

            if (pixels < width) {

                av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",

                       pixels, width);

                return AVERROR_INVALIDDATA;

            }

            break;

        }

        dst += stride;

    }

    return 0;

}

static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,

                             const uint8_t *src, int size, int lines)

{

    int c, line, pixels, code, ret;

    const uint8_t *ssrc = src;

    int width           = ((s->width * s->bpp) + 7) >> 3;



    if (size <= 0)

        return AVERROR_INVALIDDATA;



    if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {

#if CONFIG_ZLIB

        return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);

#else

        av_log(s->avctx, AV_LOG_ERROR,

               "zlib support not enabled, "

               "deflate compression not supported\n");

        return AVERROR(ENOSYS);

#endif

    }

    if (s->compr == TIFF_LZW) {

        if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {

            av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");

            return ret;

        }

    }

    if (s->compr == TIFF_CCITT_RLE ||

        s->compr == TIFF_G3        ||

        s->compr == TIFF_G4) {

        return tiff_unpack_fax(s, dst, stride, src, size, lines);

    }

    for (line = 0; line < lines; line++) {

        if (src - ssrc > size) {

            av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");

            return AVERROR_INVALIDDATA;

        }

        switch (s->compr) {

        case TIFF_RAW:

            if (ssrc + size - src < width)

                return AVERROR_INVALIDDATA;

            if (!s->fill_order) {

                memcpy(dst, src, width);

            } else {

                int i;

                for (i = 0; i < width; i++)

                    dst[i] = ff_reverse[src[i]];

            }

            src += width;

            break;

        case TIFF_PACKBITS:

            for (pixels = 0; pixels < width;) {

                code = (int8_t) *src++;

                if (code >= 0) {

                    code++;

                    if (pixels + code > width) {

                        av_log(s->avctx, AV_LOG_ERROR,

                               "Copy went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    memcpy(dst + pixels, src, code);

                    src    += code;

                    pixels += code;

                } else if (code != -128) { 

                    code = (-code) + 1;

                    if (pixels + code > width) {

                        av_log(s->avctx, AV_LOG_ERROR,

                               "Run went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    c = *src++;

                    memset(dst + pixels, c, code);

                    pixels += code;

                }

            }

            break;

        case TIFF_LZW:

            pixels = ff_lzw_decode(s->lzw, dst, width);

            if (pixels < width) {

                av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",

                       pixels, width);

                return AVERROR_INVALIDDATA;

            }

            break;

        }

        dst += stride;

    }

    return 0;

}

                    if (pixels + code > width) {
static int FUNC_0(TiffContext *VAR_0, uint8_t *VAR_1, int VAR_2,

                             const uint8_t *VAR_3, int VAR_4, int VAR_5)

{

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    const uint8_t *VAR_11 = VAR_3;

    int VAR_12           = ((VAR_0->VAR_12 * VAR_0->bpp) + 7) >> 3;



    if (VAR_4 <= 0)

        return AVERROR_INVALIDDATA;



    if (VAR_0->compr == TIFF_DEFLATE || VAR_0->compr == TIFF_ADOBE_DEFLATE) {

#if CONFIG_ZLIB

        return tiff_unpack_zlib(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_12, VAR_5);

#else

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "zlib support not enabled, "

               "deflate compression not supported\n");

        return AVERROR(ENOSYS);

#endif

    }

    if (VAR_0->compr == TIFF_LZW) {

        if ((VAR_10 = ff_lzw_decode_init(VAR_0->lzw, 8, VAR_3, VAR_4, FF_LZW_TIFF)) < 0) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");

            return VAR_10;

        }

    }

    if (VAR_0->compr == TIFF_CCITT_RLE ||

        VAR_0->compr == TIFF_G3        ||

        VAR_0->compr == TIFF_G4) {

        return tiff_unpack_fax(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

    }

    for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) {

        if (VAR_3 - VAR_11 > VAR_4) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Source data overread\n");

            return AVERROR_INVALIDDATA;

        }

        switch (VAR_0->compr) {

        case TIFF_RAW:

            if (VAR_11 + VAR_4 - VAR_3 < VAR_12)

                return AVERROR_INVALIDDATA;

            if (!VAR_0->fill_order) {

                memcpy(VAR_1, VAR_3, VAR_12);

            } else {

                int VAR_13;

                for (VAR_13 = 0; VAR_13 < VAR_12; VAR_13++)

                    VAR_1[VAR_13] = ff_reverse[VAR_3[VAR_13]];

            }

            VAR_3 += VAR_12;

            break;

        case TIFF_PACKBITS:

            for (VAR_8 = 0; VAR_8 < VAR_12;) {

                VAR_9 = (int8_t) *VAR_3++;

                if (VAR_9 >= 0) {

                    VAR_9++;

                    if (VAR_8 + VAR_9 > VAR_12) {

                        av_log(VAR_0->avctx, AV_LOG_ERROR,

                               "Copy went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    memcpy(VAR_1 + VAR_8, VAR_3, VAR_9);

                    VAR_3    += VAR_9;

                    VAR_8 += VAR_9;

                } else if (VAR_9 != -128) { 

                    VAR_9 = (-VAR_9) + 1;

                    if (VAR_8 + VAR_9 > VAR_12) {

                        av_log(VAR_0->avctx, AV_LOG_ERROR,

                               "Run went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    VAR_6 = *VAR_3++;

                    memset(VAR_1 + VAR_8, VAR_6, VAR_9);

                    VAR_8 += VAR_9;

                }

            }

            break;

        case TIFF_LZW:

            VAR_8 = ff_lzw_decode(VAR_0->lzw, VAR_1, VAR_12);

            if (VAR_8 < VAR_12) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Decoded only %VAR_13 bytes of %VAR_13\n",

                       VAR_8, VAR_12);

                return AVERROR_INVALIDDATA;

            }

            break;

        }

        VAR_1 += VAR_2;

    }

    return 0;

}

static int FUNC_0(TiffContext *VAR_0, uint8_t *VAR_1, int VAR_2,
const uint8_t *VAR_3, int VAR_4, int VAR_5)
{ int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; const uint8_t *VAR_11 = VAR_3; int VAR_12           = ((VAR_0->VAR_12 * VAR_0->bpp) + 7) >> 3; if (VAR_4 <= 0)
return AVERROR_INVALIDDATA; if (VAR_0->compr == TIFF_DEFLATE || VAR_0->compr == TIFF_ADOBE_DEFLATE) { #if CONFIG_ZLIB
return tiff_unpack_zlib(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_12, VAR_5); #else
av_log(VAR_0->avctx, AV_LOG_ERROR,
"zlib support not enabled, "
"deflate compression not supported\n"); return AVERROR(ENOSYS); #endif
} if (VAR_0->compr == TIFF_LZW) { if ((VAR_10 = ff_lzw_decode_init(VAR_0->lzw, 8, VAR_3, VAR_4, FF_LZW_TIFF)) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); return VAR_10; } } if (VAR_0->compr == TIFF_CCITT_RLE ||
VAR_0->compr == TIFF_G3        ||
VAR_0->compr == TIFF_G4) { return tiff_unpack_fax(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); } for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { if (VAR_3 - VAR_11 > VAR_4) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Source data overread\n"); return AVERROR_INVALIDDATA; } switch (VAR_0->compr) { case TIFF_RAW:
if (VAR_11 + VAR_4 - VAR_3 < VAR_12)
return AVERROR_INVALIDDATA; if (!VAR_0->fill_order) { memcpy(VAR_1, VAR_3, VAR_12); } else { int VAR_13; for (VAR_13 = 0; VAR_13 < VAR_12; VAR_13++) VAR_1[VAR_13] = ff_reverse[VAR_3[VAR_13]]; } VAR_3 += VAR_12; break; case TIFF_PACKBITS:
for (VAR_8 = 0; VAR_8 < VAR_12;) { VAR_9 = (int8_t) *VAR_3++; if (VAR_9 >= 0) { VAR_9++; if (VAR_8 + VAR_9 > VAR_12) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Copy went out of bounds\n"); return AVERROR_INVALIDDATA; } memcpy(VAR_1 + VAR_8, VAR_3, VAR_9); VAR_3    += VAR_9; VAR_8 += VAR_9; } else if (VAR_9 != -128) { VAR_9 = (-VAR_9) + 1; if (VAR_8 + VAR_9 > VAR_12) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Run went out of bounds\n"); return AVERROR_INVALIDDATA; } VAR_6 = *VAR_3++; memset(VAR_1 + VAR_8, VAR_6, VAR_9); VAR_8 += VAR_9; } } break; case TIFF_LZW:
VAR_8 = ff_lzw_decode(VAR_0->lzw, VAR_1, VAR_12); if (VAR_8 < VAR_12) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Decoded only %VAR_13 bytes of %VAR_13\n",
VAR_8, VAR_12); return AVERROR_INVALIDDATA; } break; } VAR_1 += VAR_2; } return 0; }