Reject white points that would divide by zero

Fuzzing Skia's PNG decoders produced a cHRM chunk with a white point y
of 0. skcms_AdaptToXYZD50() and skcms_PrimariesToXYZD50() only check
that the white point is in [0, 1] before dividing by y, so this
triggered float-divide-by-zero in UBSan and, in production, returned
true with a NaN matrix, which Skia turned into a color profile that
decodes the whole image black.

Reject a zero y, as well as a zero Bradford cone response in
skcms_AdaptToXYZD50() (reachable with in-range white points far outside
the spectral locus). Also fail if the resulting matrix is not finite,
since a denormal y passes the zero checks but still overflows to
inf/NaN.

Bug: b/562799124
Change-Id: Ibe48fd3f7abf64286eb81e82c176c830d214f036
Reviewed-on: https://skia-review.googlesource.com/c/skcms/+/1386676
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
3 files changed
tree: 51a563316814ab03395169ce68820a98c3b29470
  1. bazel/
  2. fuzz/
  3. infra/
  4. ninja/
  5. profiles/
  6. src/
  7. toolchain/
  8. .bazelrc
  9. .bazelversion
  10. .gitignore
  11. BAZEL.md
  12. bench.c
  13. BUILD.bazel
  14. build.ninja
  15. codereview.settings
  16. iccdump.c
  17. LICENSE
  18. MODULE.bazel
  19. MODULE.bazel.lock
  20. msvs.ninja
  21. OWNERS
  22. README.chromium
  23. README.md
  24. skcms.cc
  25. skcms.gni
  26. skcms.h
  27. test_only.c
  28. test_only.h
  29. tests.c
  30. whitespace.txt
README.md

To build with ninja, simply run ninja from the root directory. This will produce a library in /out.

There are also Bazel rules, outlined in BAZEL.md