2014.12.27 23:06 "[Tiff] [PATCH] tiff2ps: fix grayscale with unassociated alpha (and other extrasamples != 0)", by Yuriy M. Kaminskiy

2015.01.04 23:02 "Re: [Tiff] [PATCH] tif_luv, tif_pixarlog, ppm2tiff: get rid of duplicates of TIFFSafeMultiply", by Yuriy M. Kaminskiy

Jürgen Buchmüller wrote:

> Am Dienstag, den 30.12.2014, 23:41 +0300 schrieb Yuriy M. Kaminskiy:
>> While fixing that, I noticed some very WTF code: add_ms in
>> libtiff/tif_pixarlog.c and checkAdd64 in tools/tiff2pdf.c
>> I'm not sure what are they trying to do, but I'm pretty sure they are doing it
>> WRONG and both cannot possibly work, due to different reasons. Please take a
>> look or two.
>
> I don't see add_ms in my copy (4.0.3) of the source. multiply_ms looks

like it could work, though.

At first, I've thought so too. However, now I'm not so sure: as signed overflow is not defined, when type is signed (and tmsize_t is signed), compiler is free to believe "(a*b)/b == a" is always true, and get rid of this check. Obviously, this affects TIFFSafeMultiply too (it uses exactly same code).

For checkAdd64 I also don't see how it could work as intended.

Perhaps this line would work

        if ((summand1/2 + summand2/2 + 1) & (1ull << 63)) {