diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2009-09-27 07:01:01 +0000 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2009-09-27 07:01:01 +0000 |
commit | e96f885aa092958cc0d54bbb191b82a0796518a4 (patch) | |
tree | 5d0e191fd908a55a9f81193fa43b41b00dfbb5e4 /libavcodec/tiff.c | |
parent | 3b6c5ad2f67cc8eeeec89fb9d497ec79c1f3948a (diff) | |
download | ffmpeg-e96f885aa092958cc0d54bbb191b82a0796518a4.tar.gz |
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
so replace it with custom code.
This fixes issue 1419.
Originally committed as revision 20054 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/tiff.c')
-rw-r--r-- | libavcodec/tiff.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index af7b40e3ca..263f2874a1 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -75,6 +75,27 @@ static int tget(const uint8_t **p, int type, int le){ } } +static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src, int size) +{ + z_stream zstream; + int zret; + + memset(&zstream, 0, sizeof(zstream)); + zstream.next_in = src; + zstream.avail_in = size; + zstream.next_out = dst; + zstream.avail_out = *len; + zret = inflateInit(&zstream); + if (zret != Z_OK) { + av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return zret; + } + zret = inflate(&zstream, Z_SYNC_FLUSH); + inflateEnd(&zstream); + *len = zstream.total_out; + return zret == Z_STREAM_END ? Z_OK : zret; +} + 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; const uint8_t *ssrc = src; @@ -83,10 +104,12 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin uint8_t *zbuf; unsigned long outlen; if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){ + int ret; outlen = width * lines; zbuf = av_malloc(outlen); - if(uncompress(zbuf, &outlen, src, size) != Z_OK){ - av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu)\n", outlen, (unsigned long)width * lines); + ret = tiff_uncompress(zbuf, &outlen, src, size); + if(ret != Z_OK){ + av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu) with error %d\n", outlen, (unsigned long)width * lines, ret); av_free(zbuf); return -1; } |