Re: DWA compression: fails due to insufficient buffer size

Karl Rasche <[email protected]>
Newsgroups gmane.comp.video.openexr.devel
Message-ID <CAD5HwvRgXZBU++6cPZ5F+xDZ8GBPJ12gz8mhpgsg3nC5t6odNw@mail.gmail.com>
Vasil -

By any chance do you have an image you can share that trips this problem?
There are a couple of other places where compressBound() would be good to
use.

Thanks!
karl

On Thursday, January 22, 2015, Vasil Minkov <[email protected]>
wrote:

> Hello,
>
> While tracking an error report I found an issue with the DWA compression -
> it fails to compress certain input data.
> The problem is easily reproduced on attempt to store a small (8x8 pixels)
> single-channel (Luma only) EXR image using DWA compression.
> An exception "Data compression (zlib) failed." is thrown in such case. The
> problem also occurs when compressing small and noisy RGB tiles.
>
> It seems that the problem is in ImfDwaCompressor.cpp, in the following
> code fragment:
>
>                 ......
>                 uLongf destLen = (uLongf)
>                     (2 * (*totalAcUncompressedCount) * sizeof (unsigned
> short));
>
>                 if (Z_OK != ::compress2
>                                 ((Bytef *)outDataPtr,
> &destLen,
>                                  (Bytef *)_packedAcBuffer,
>                                  (uLong)(*totalAcUncompressedCount
>                                                 * sizeof (unsigned short)),
>                                  9))
>                 ......
>
> Under certain circumstances compress2() output size may exceed its input
> size, as specified in zlib's docs.
> Here is my fix of the problem:
>
>                 ......
>                 uLongf destLen = (uLongf)
>                     (2 * (*totalAcUncompressedCount) * sizeof (unsigned
> short));
>                 // compress2 requirement:
>                 //   "Upon entry, destLen is the total size of the
>                 //   destination buffer, which must be at least 0.1% larger
>                 //   than sourceLen plus 12 bytes"
>                 // Fulfill the above requirement in integer arithmetic
>                 destLen=((Int64)destLen*1001 + 1000)/1000 + 12;
>                 if (Z_OK != ::compress2
>                                 ((Bytef *)outDataPtr,
> &destLen,
>                                  (Bytef *)_packedAcBuffer,
>                                  (uLong)(*totalAcUncompressedCount
>                                                 * sizeof (unsigned short)),
>                                  9))
>                 ......
>
> zlib's ::compressBound() could also be used to calculate the buffer size.
>
> Regards,
>
> --
> Vasil Minkov
>
> VRay for 3ds Max developer
>
>
> _______________________________________________
> Openexr-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/openexr-devel
>

_______________________________________________
Openexr-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/openexr-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.