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

                             const uint8_t *src, int size, int strip_start, int lines)

{

    PutByteContext pb;

    int c, line, pixels, code, ret;

    const uint8_t *ssrc = src;

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

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(p->format);

    int is_yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;



    if (s->planar)

        width /= s->bppcount;



    if (size <= 0)

        return AVERROR_INVALIDDATA;



    if (is_yuv) {

        int bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp *

                            s->subsampling[0] * s->subsampling[1] + 7) >> 3;

        av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);

        if (s->yuv_line == NULL) {

            av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");

            return AVERROR(ENOMEM);

        }

        dst = s->yuv_line;

        stride = 0;

        width = s->width * s->subsampling[1] + 2*(s->width / s->subsampling[0]);

        av_assert0(width <= bytes_per_row);

        av_assert0(s->bpp == 24);

    }



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

#if CONFIG_ZLIB

        return tiff_unpack_zlib(s, p, dst, stride, src, size, width, lines,

                                strip_start, is_yuv);

#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_LZMA) {

#if CONFIG_LZMA

        return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,

                                strip_start, is_yuv);

#else

        av_log(s->avctx, AV_LOG_ERROR,

               "LZMA support not enabled\n");

        return AVERROR(ENOSYS);

#endif

    }

    if (s->compr == TIFF_LZW) {

        if (s->fill_order) {

            if ((ret = deinvert_buffer(s, src, size)) < 0)

                return ret;

            ssrc = src = s->deinvert_buf;

        }

        if (size > 1 && !src[0] && (src[1]&1)) {

            av_log(s->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n");

        }

        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;

        }

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

            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;

            }

            if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)

                horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);

            if (is_yuv) {

                unpack_yuv(s, p, dst, strip_start + line);

                line += s->subsampling[1] - 1;

            }

            dst += stride;

        }

        return 0;

    }

    if (s->compr == TIFF_CCITT_RLE ||

        s->compr == TIFF_G3        ||

        s->compr == TIFF_G4) {

        if (is_yuv)

            return AVERROR_INVALIDDATA;



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

    }



    bytestream2_init(&s->gb, src, size);

    bytestream2_init_writer(&pb, dst, is_yuv ? s->yuv_line_size : (stride * 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;

        }



        if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))

            break;

        bytestream2_seek_p(&pb, stride * line, SEEK_SET);

        switch (s->compr) {

        case TIFF_RAW:

            if (ssrc + size - src < width)

                return AVERROR_INVALIDDATA;



            if (!s->fill_order) {

                horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                dst, 1, src, 0, width, 0);

            } 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;) {

                if (ssrc + size - src < 2) {

                    av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");

                    return AVERROR_INVALIDDATA;

                }

                code = s->fill_order ? (int8_t) ff_reverse[*src++]: (int8_t) *src++;

                if (code >= 0) {

                    code++;

                    if (pixels + code > width ||

                        ssrc + size - src < code) {

                        av_log(s->avctx, AV_LOG_ERROR,

                               "Copy went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                    dst, 1, src, 0, code, pixels);

                    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++;

                    horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                    dst, 0, NULL, c, code, pixels);

                    pixels += code;

                }

            }

            if (s->fill_order) {

                int i;

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

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

            }

            break;

        }

        if (is_yuv) {

            unpack_yuv(s, p, dst, strip_start + line);

            line += s->subsampling[1] - 1;

        }

        dst += stride;

    }

    return 0;

}

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

                             const uint8_t *src, int size, int strip_start, int lines)

{

    PutByteContext pb;

    int c, line, pixels, code, ret;

    const uint8_t *ssrc = src;

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

    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(p->format);

    int is_yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;



    if (s->planar)

        width /= s->bppcount;



    if (size <= 0)

        return AVERROR_INVALIDDATA;



    if (is_yuv) {

        int bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp *

                            s->subsampling[0] * s->subsampling[1] + 7) >> 3;

        av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);

        if (s->yuv_line == NULL) {

            av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");

            return AVERROR(ENOMEM);

        }

        dst = s->yuv_line;

        stride = 0;

        width = s->width * s->subsampling[1] + 2*(s->width / s->subsampling[0]);

        av_assert0(width <= bytes_per_row);

        av_assert0(s->bpp == 24);

    }



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

#if CONFIG_ZLIB

        return tiff_unpack_zlib(s, p, dst, stride, src, size, width, lines,

                                strip_start, is_yuv);

#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_LZMA) {

#if CONFIG_LZMA

        return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,

                                strip_start, is_yuv);

#else

        av_log(s->avctx, AV_LOG_ERROR,

               "LZMA support not enabled\n");

        return AVERROR(ENOSYS);

#endif

    }

    if (s->compr == TIFF_LZW) {

        if (s->fill_order) {

            if ((ret = deinvert_buffer(s, src, size)) < 0)

                return ret;

            ssrc = src = s->deinvert_buf;

        }

        if (size > 1 && !src[0] && (src[1]&1)) {

            av_log(s->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n");

        }

        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;

        }

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

            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;

            }

            if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)

                horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);

            if (is_yuv) {

                unpack_yuv(s, p, dst, strip_start + line);

                line += s->subsampling[1] - 1;

            }

            dst += stride;

        }

        return 0;

    }

    if (s->compr == TIFF_CCITT_RLE ||

        s->compr == TIFF_G3        ||

        s->compr == TIFF_G4) {

        if (is_yuv)

            return AVERROR_INVALIDDATA;



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

    }



    bytestream2_init(&s->gb, src, size);

    bytestream2_init_writer(&pb, dst, is_yuv ? s->yuv_line_size : (stride * 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;

        }



        if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))

            break;

        bytestream2_seek_p(&pb, stride * line, SEEK_SET);

        switch (s->compr) {

        case TIFF_RAW:

            if (ssrc + size - src < width)

                return AVERROR_INVALIDDATA;



            if (!s->fill_order) {

                horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                dst, 1, src, 0, width, 0);

            } 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;) {

                if (ssrc + size - src < 2) {

                    av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");

                    return AVERROR_INVALIDDATA;

                }

                code = s->fill_order ? (int8_t) ff_reverse[*src++]: (int8_t) *src++;

                if (code >= 0) {

                    code++;

                    if (pixels + code > width ||

                        ssrc + size - src < code) {

                        av_log(s->avctx, AV_LOG_ERROR,

                               "Copy went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                    dst, 1, src, 0, code, pixels);

                    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++;

                    horizontal_fill(s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                    dst, 0, NULL, c, code, pixels);

                    pixels += code;

                }

            }

            if (s->fill_order) {

                int i;

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

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

            }

            break;

        }

        if (is_yuv) {

            unpack_yuv(s, p, dst, strip_start + line);

            line += s->subsampling[1] - 1;

        }

        dst += stride;

    }

    return 0;

}

    int is_yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2;
static int FUNC_0(TiffContext *VAR_0, AVFrame *VAR_1, uint8_t *VAR_2, int VAR_3,

                             const uint8_t *VAR_4, int VAR_5, int VAR_6, int VAR_7)

{

    PutByteContext pb;

    int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12;

    const uint8_t *VAR_13 = VAR_4;

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

    const AVPixFmtDescriptor *VAR_15 = av_pix_fmt_desc_get(VAR_1->format);

    int VAR_16 = !(VAR_15->flags & AV_PIX_FMT_FLAG_RGB) && VAR_15->nb_components >= 2;



    if (VAR_0->planar)

        VAR_14 /= VAR_0->bppcount;



    if (VAR_5 <= 0)

        return AVERROR_INVALIDDATA;



    if (VAR_16) {

        int VAR_17 = (((VAR_0->VAR_14 - 1) / VAR_0->subsampling[0] + 1) * VAR_0->bpp *

                            VAR_0->subsampling[0] * VAR_0->subsampling[1] + 7) >> 3;

        av_fast_padded_malloc(&VAR_0->yuv_line, &VAR_0->yuv_line_size, VAR_17);

        if (VAR_0->yuv_line == NULL) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Not enough memory\n");

            return AVERROR(ENOMEM);

        }

        VAR_2 = VAR_0->yuv_line;

        VAR_3 = 0;

        VAR_14 = VAR_0->VAR_14 * VAR_0->subsampling[1] + 2*(VAR_0->VAR_14 / VAR_0->subsampling[0]);

        av_assert0(VAR_14 <= VAR_17);

        av_assert0(VAR_0->bpp == 24);

    }



    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_5, VAR_14, VAR_7,

                                VAR_6, VAR_16);

#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_LZMA) {

#if CONFIG_LZMA

        return tiff_unpack_lzma(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_14, VAR_7,

                                VAR_6, VAR_16);

#else

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "LZMA support not enabled\n");

        return AVERROR(ENOSYS);

#endif

    }

    if (VAR_0->compr == TIFF_LZW) {

        if (VAR_0->fill_order) {

            if ((VAR_12 = deinvert_buffer(VAR_0, VAR_4, VAR_5)) < 0)

                return VAR_12;

            VAR_13 = VAR_4 = VAR_0->deinvert_buf;

        }

        if (VAR_5 > 1 && !VAR_4[0] && (VAR_4[1]&1)) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n");

        }

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

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

            return VAR_12;

        }

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

            VAR_10 = ff_lzw_decode(VAR_0->lzw, VAR_2, VAR_14);

            if (VAR_10 < VAR_14) {

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

                       VAR_10, VAR_14);

                return AVERROR_INVALIDDATA;

            }

            if (VAR_0->bpp < 8 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8)

                horizontal_fill(VAR_0->bpp, VAR_2, 1, VAR_2, 0, VAR_14, 0);

            if (VAR_16) {

                unpack_yuv(VAR_0, VAR_1, VAR_2, VAR_6 + VAR_9);

                VAR_9 += VAR_0->subsampling[1] - 1;

            }

            VAR_2 += VAR_3;

        }

        return 0;

    }

    if (VAR_0->compr == TIFF_CCITT_RLE ||

        VAR_0->compr == TIFF_G3        ||

        VAR_0->compr == TIFF_G4) {

        if (VAR_16)

            return AVERROR_INVALIDDATA;



        return tiff_unpack_fax(VAR_0, VAR_2, VAR_3, VAR_4, VAR_5, VAR_14, VAR_7);

    }



    bytestream2_init(&VAR_0->gb, VAR_4, VAR_5);

    bytestream2_init_writer(&pb, VAR_2, VAR_16 ? VAR_0->yuv_line_size : (VAR_3 * VAR_7));



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

        if (VAR_4 - VAR_13 > VAR_5) {

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

            return AVERROR_INVALIDDATA;

        }



        if (bytestream2_get_bytes_left(&VAR_0->gb) == 0 || bytestream2_get_eof(&pb))

            break;

        bytestream2_seek_p(&pb, VAR_3 * VAR_9, SEEK_SET);

        switch (VAR_0->compr) {

        case TIFF_RAW:

            if (VAR_13 + VAR_5 - VAR_4 < VAR_14)

                return AVERROR_INVALIDDATA;



            if (!VAR_0->fill_order) {

                horizontal_fill(VAR_0->bpp * (VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                VAR_2, 1, VAR_4, 0, VAR_14, 0);

            } else {

                int VAR_19;

                for (VAR_19 = 0; VAR_19 < VAR_14; VAR_19++)

                    VAR_2[VAR_19] = ff_reverse[VAR_4[VAR_19]];

            }

            VAR_4 += VAR_14;

            break;

        case TIFF_PACKBITS:

            for (VAR_10 = 0; VAR_10 < VAR_14;) {

                if (VAR_13 + VAR_5 - VAR_4 < 2) {

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Read went out of bounds\n");

                    return AVERROR_INVALIDDATA;

                }

                VAR_11 = VAR_0->fill_order ? (int8_t) ff_reverse[*VAR_4++]: (int8_t) *VAR_4++;

                if (VAR_11 >= 0) {

                    VAR_11++;

                    if (VAR_10 + VAR_11 > VAR_14 ||

                        VAR_13 + VAR_5 - VAR_4 < VAR_11) {

                        av_log(VAR_0->avctx, AV_LOG_ERROR,

                               "Copy went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    horizontal_fill(VAR_0->bpp * (VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                    VAR_2, 1, VAR_4, 0, VAR_11, VAR_10);

                    VAR_4    += VAR_11;

                    VAR_10 += VAR_11;

                } else if (VAR_11 != -128) { 

                    VAR_11 = (-VAR_11) + 1;

                    if (VAR_10 + VAR_11 > VAR_14) {

                        av_log(VAR_0->avctx, AV_LOG_ERROR,

                               "Run went out of bounds\n");

                        return AVERROR_INVALIDDATA;

                    }

                    VAR_8 = *VAR_4++;

                    horizontal_fill(VAR_0->bpp * (VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8),

                                    VAR_2, 0, NULL, VAR_8, VAR_11, VAR_10);

                    VAR_10 += VAR_11;

                }

            }

            if (VAR_0->fill_order) {

                int VAR_19;

                for (VAR_19 = 0; VAR_19 < VAR_14; VAR_19++)

                    VAR_2[VAR_19] = ff_reverse[VAR_2[VAR_19]];

            }

            break;

        }

        if (VAR_16) {

            unpack_yuv(VAR_0, VAR_1, VAR_2, VAR_6 + VAR_9);

            VAR_9 += VAR_0->subsampling[1] - 1;

        }

        VAR_2 += VAR_3;

    }

    return 0;

}

static int FUNC_0(TiffContext *VAR_0, AVFrame *VAR_1, uint8_t *VAR_2, int VAR_3,
const uint8_t *VAR_4, int VAR_5, int VAR_6, int VAR_7)
{ PutByteContext pb; int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12; const uint8_t *VAR_13 = VAR_4; int VAR_14 = ((VAR_0->VAR_14 * VAR_0->bpp) + 7) >> 3; const AVPixFmtDescriptor *VAR_15 = av_pix_fmt_desc_get(VAR_1->format); int VAR_16 = !(VAR_15->flags & AV_PIX_FMT_FLAG_RGB) && VAR_15->nb_components >= 2; if (VAR_0->planar)
VAR_14 /= VAR_0->bppcount; if (VAR_5 <= 0)
return AVERROR_INVALIDDATA; if (VAR_16) { int VAR_17 = (((VAR_0->VAR_14 - 1) / VAR_0->subsampling[0] + 1) * VAR_0->bpp *
VAR_0->subsampling[0] * VAR_0->subsampling[1] + 7) >> 3; av_fast_padded_malloc(&VAR_0->yuv_line, &VAR_0->yuv_line_size, VAR_17); if (VAR_0->yuv_line == NULL) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Not enough memory\n"); return AVERROR(ENOMEM); } VAR_2 = VAR_0->yuv_line; VAR_3 = 0; VAR_14 = VAR_0->VAR_14 * VAR_0->subsampling[1] + 2*(VAR_0->VAR_14 / VAR_0->subsampling[0]); av_assert0(VAR_14 <= VAR_17); av_assert0(VAR_0->bpp == 24); } 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_5, VAR_14, VAR_7,
VAR_6, VAR_16); #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_LZMA) { #if CONFIG_LZMA
return tiff_unpack_lzma(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_14, VAR_7,
VAR_6, VAR_16); #else
av_log(VAR_0->avctx, AV_LOG_ERROR,
"LZMA support not enabled\n"); return AVERROR(ENOSYS); #endif
} if (VAR_0->compr == TIFF_LZW) { if (VAR_0->fill_order) { if ((VAR_12 = deinvert_buffer(VAR_0, VAR_4, VAR_5)) < 0)
return VAR_12; VAR_13 = VAR_4 = VAR_0->deinvert_buf; } if (VAR_5 > 1 && !VAR_4[0] && (VAR_4[1]&1)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n"); } if ((VAR_12 = ff_lzw_decode_init(VAR_0->lzw, 8, VAR_4, VAR_5, FF_LZW_TIFF)) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); return VAR_12; } for (VAR_9 = 0; VAR_9 < VAR_7; VAR_9++) { VAR_10 = ff_lzw_decode(VAR_0->lzw, VAR_2, VAR_14); if (VAR_10 < VAR_14) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Decoded only %VAR_19 bytes of %VAR_19\n",
VAR_10, VAR_14); return AVERROR_INVALIDDATA; } if (VAR_0->bpp < 8 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8)
horizontal_fill(VAR_0->bpp, VAR_2, 1, VAR_2, 0, VAR_14, 0); if (VAR_16) { unpack_yuv(VAR_0, VAR_1, VAR_2, VAR_6 + VAR_9); VAR_9 += VAR_0->subsampling[1] - 1; } VAR_2 += VAR_3; } return 0; } if (VAR_0->compr == TIFF_CCITT_RLE ||
VAR_0->compr == TIFF_G3        ||
VAR_0->compr == TIFF_G4) { if (VAR_16)
return AVERROR_INVALIDDATA; return tiff_unpack_fax(VAR_0, VAR_2, VAR_3, VAR_4, VAR_5, VAR_14, VAR_7); } bytestream2_init(&VAR_0->gb, VAR_4, VAR_5); bytestream2_init_writer(&pb, VAR_2, VAR_16 ? VAR_0->yuv_line_size : (VAR_3 * VAR_7)); for (VAR_9 = 0; VAR_9 < VAR_7; VAR_9++) { if (VAR_4 - VAR_13 > VAR_5) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Source data overread\n"); return AVERROR_INVALIDDATA; } if (bytestream2_get_bytes_left(&VAR_0->gb) == 0 || bytestream2_get_eof(&pb))
break; bytestream2_seek_p(&pb, VAR_3 * VAR_9, SEEK_SET); switch (VAR_0->compr) { case TIFF_RAW:
if (VAR_13 + VAR_5 - VAR_4 < VAR_14)
return AVERROR_INVALIDDATA; if (!VAR_0->fill_order) { horizontal_fill(VAR_0->bpp * (VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8),
VAR_2, 1, VAR_4, 0, VAR_14, 0); } else { int VAR_19; for (VAR_19 = 0; VAR_19 < VAR_14; VAR_19++) VAR_2[VAR_19] = ff_reverse[VAR_4[VAR_19]]; } VAR_4 += VAR_14; break; case TIFF_PACKBITS:
for (VAR_10 = 0; VAR_10 < VAR_14;) { if (VAR_13 + VAR_5 - VAR_4 < 2) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Read went out of bounds\n"); return AVERROR_INVALIDDATA; } VAR_11 = VAR_0->fill_order ? (int8_t) ff_reverse[*VAR_4++]: (int8_t) *VAR_4++; if (VAR_11 >= 0) { VAR_11++; if (VAR_10 + VAR_11 > VAR_14 ||
VAR_13 + VAR_5 - VAR_4 < VAR_11) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Copy went out of bounds\n"); return AVERROR_INVALIDDATA; } horizontal_fill(VAR_0->bpp * (VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8),
VAR_2, 1, VAR_4, 0, VAR_11, VAR_10); VAR_4    += VAR_11; VAR_10 += VAR_11; } else if (VAR_11 != -128) { VAR_11 = (-VAR_11) + 1; if (VAR_10 + VAR_11 > VAR_14) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Run went out of bounds\n"); return AVERROR_INVALIDDATA; } VAR_8 = *VAR_4++; horizontal_fill(VAR_0->bpp * (VAR_0->avctx->pix_fmt == AV_PIX_FMT_PAL8),
VAR_2, 0, NULL, VAR_8, VAR_11, VAR_10); VAR_10 += VAR_11; } } if (VAR_0->fill_order) { int VAR_19; for (VAR_19 = 0; VAR_19 < VAR_14; VAR_19++) VAR_2[VAR_19] = ff_reverse[VAR_2[VAR_19]]; } break; } if (VAR_16) { unpack_yuv(VAR_0, VAR_1, VAR_2, VAR_6 + VAR_9); VAR_9 += VAR_0->subsampling[1] - 1; } VAR_2 += VAR_3; } return 0; }