Fix invalid conversion from RGB8 to CMYK32 due to overflow by mloskot · Pull Request #470 · boostorg/gil

simmplecoder

@mloskot mloskot changed the title Fix overflow in RGB to CMYK32 conversion Fix invalid conversion from RGB8 to CMYK32 due to overflow

Mar 31, 2020

@mloskot

Correct calculation to correctly map CMYK 0 to minimum
and 1 to maximum of input and output channel types.

If float-point division is necessary, use double instead of float
which may be too narrow for large operands. cmyk32_pixel_t is based on
uint32_t which multiplication by its maximum may yield result too
large to fit 32-bit float.

For example, (uint32_t(c) -  uint32_t(k)) * float(s) for
  c = 4294967295, k = 0, s = 1.0
results in 4294967300 value which does not fit uint32_t.

Fixes boostorg#406

@mloskot mloskot marked this pull request as ready for review

April 9, 2020 21:39

@mloskot mloskot deleted the ml/fix-rgb-to-cmyk32-fp-overflow branch

April 10, 2020 17:12

mloskot added a commit that referenced this pull request

Jul 11, 2020
* develop:
  Collect release notes for Boost 1.74
  Fix missing header in numeric/kernel.hpp to make it self-contained (#502)
  Use perfect forwading from apply_operation to visit (#491)
  Fix typos and replace mpl with mp11 in tutorial (#494)
  Implemented mechanism to reverse kernel_2d (#489)
  added missing const& in extend_boundary parameters (#490)
  Add initializing image constructor (#486)
  Fix interleaved_view factory using point<std::ptrdiff_t> for dimension (#487)
  RELEASES.md: Remove beta tag [ci skip]
  Replace Boost.Variant with Boost.Variant2 (#474)
  Fix error plane_view_t is not a class or namespace name (#481)
  Fix image constructor from other image (#477)
  Fix overflow in RGB to CMYK32 conversion (#470)