comparison tiff.c @ 10296:a919d9583abd libavcodec

Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data, so replace it with custom code. This fixes issue 1419.
author kostya
date Sun, 27 Sep 2009 07:01:01 +0000
parents f9efc2bd005d
children a1654cd1b5b9
comparison
equal deleted inserted replaced
10295:916c2b7ecd02 10296:a919d9583abd
73 case TIFF_LONG : return tget_long (p, le); 73 case TIFF_LONG : return tget_long (p, le);
74 default : return -1; 74 default : return -1;
75 } 75 }
76 } 76 }
77 77
78 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src, int size)
79 {
80 z_stream zstream;
81 int zret;
82
83 memset(&zstream, 0, sizeof(zstream));
84 zstream.next_in = src;
85 zstream.avail_in = size;
86 zstream.next_out = dst;
87 zstream.avail_out = *len;
88 zret = inflateInit(&zstream);
89 if (zret != Z_OK) {
90 av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
91 return zret;
92 }
93 zret = inflate(&zstream, Z_SYNC_FLUSH);
94 inflateEnd(&zstream);
95 *len = zstream.total_out;
96 return zret == Z_STREAM_END ? Z_OK : zret;
97 }
98
78 static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){ 99 static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){
79 int c, line, pixels, code; 100 int c, line, pixels, code;
80 const uint8_t *ssrc = src; 101 const uint8_t *ssrc = src;
81 int width = s->width * s->bpp >> 3; 102 int width = s->width * s->bpp >> 3;
82 #if CONFIG_ZLIB 103 #if CONFIG_ZLIB
83 uint8_t *zbuf; unsigned long outlen; 104 uint8_t *zbuf; unsigned long outlen;
84 105
85 if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){ 106 if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){
107 int ret;
86 outlen = width * lines; 108 outlen = width * lines;
87 zbuf = av_malloc(outlen); 109 zbuf = av_malloc(outlen);
88 if(uncompress(zbuf, &outlen, src, size) != Z_OK){ 110 ret = tiff_uncompress(zbuf, &outlen, src, size);
89 av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu)\n", outlen, (unsigned long)width * lines); 111 if(ret != Z_OK){
112 av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu) with error %d\n", outlen, (unsigned long)width * lines, ret);
90 av_free(zbuf); 113 av_free(zbuf);
91 return -1; 114 return -1;
92 } 115 }
93 src = zbuf; 116 src = zbuf;
94 for(line = 0; line < lines; line++){ 117 for(line = 0; line < lines; line++){