Ticket #2006: tiff_lzw3.diff

File tiff_lzw3.diff, 1.8 KB (added by ami_stuff, 14 years ago)
  • libavcodec/tiff.c

    diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
    index 286cbc2..54fafa8 100644
    a b static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,  
    398398{
    399399    int c, line, pixels, code;
    400400    const uint8_t *ssrc = src;
     401    uint8_t *src2 = NULL;
    401402    int width = ((s->width * s->bpp) + 7) >> 3;
    402403
    403404    if (size <= 0)
    … … static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,  
    449450    }
    450451#endif
    451452    if (s->compr == TIFF_LZW) {
     453        if (s->fill_order) {
     454            int i;
     455            src2 = av_malloc((unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE);
     456            if (!src2) {
     457                av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
     458                return AVERROR(ENOMEM);
     459            }
     460            for (i = 0; i < size; i++)
     461                src2[i] = ff_reverse[src[i]];
     462            memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
     463            src = src2;
     464            ssrc = src;
     465        }
    452466        if (ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0) {
    453467            av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
     468            av_free(src2);
    454469            return -1;
    455470        }
    456471    }
    … … static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,  
    554569            if (pixels < width) {
    555570                av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
    556571                       pixels, width);
     572                av_free(src2);
    557573                return -1;
    558574            }
    559575            if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
    560576                horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
     577            av_free(src2);
    561578            break;
    562579        }
    563580        dst += stride;