+ av_free(zbuf);
+ return 0;
+}
+#endif
+
+
+static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
+ const uint8_t *src, int size, int lines)
+{
+ int i, ret = 0;
+ uint8_t *src2 = av_malloc((unsigned)size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
+
+ if (!src2) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Error allocating temporary buffer\n");
+ return AVERROR(ENOMEM);
+ }
+ if (s->fax_opts & 2) {
+ avpriv_request_sample(s->avctx, "Uncompressed fax mode");
+ av_free(src2);
+ return AVERROR_PATCHWELCOME;
+ }
+ if (!s->fill_order) {
+ memcpy(src2, src, size);
+ } else {
+ for (i = 0; i < size; i++)
+ src2[i] = ff_reverse[src[i]];
+ }
+ memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
+ s->compr, s->fax_opts);
+ av_free(src2);
+ return ret;
+}
+
+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);