• DRC's avatar
    TurboJPEG: Ensure 'pad' arg is a power of 2 · d2608583
    DRC authored
    Because the PAD() macro can only handle powers of 2, this is a necessary
    restriction (and a documented one, except in the case of
    tjCompressFromYUV()-- oops.)  Failing to check the 'pad' argument
    caused tjBufSizeYUV2() to return bogus results if 'pad' was less than 1
    or otherwise not a power of 2.  tjEncodeYUV3() and tjDecodeYUV()
    effectively treated a 'pad' value of 0 as unpadded, but that was subtle
    and undocumented behavior.  tjCompressFromYUV() did not check whether
    'pad' was a power of 2, so the strides passed to
    tjCompressFromYUVPlanes() would have been incorrect if 'pad' was not a
    power of 2.  That would not have caused tjCompressFromYUV() to overrun
    the source buffer, as long as the calling application allocated the
    buffer based on the return value of tjBufSizeYUV2() (which computes the
    strides in the same manner as tjCompressFromYUV().)  However, if the
    calling application attempted to initialize the source buffer using
    correctly-computed strides, then it could have overrun its own
    buffer in certain cases or produced incorrect JPEG images in others.
    
    Realistically, there is no reason why an application would want to pass
    a non-power-of-2 'pad' value to a TurboJPEG API function, so this commit
    is about user-proofing the API rather than fixing any known issue.
    d2608583
This project is licensed under the zlib License. Learn more