libjxl
libjxl copied to clipboard
Floating Point overflow in FindBestSplit()
Describe the bug In the code, two values, both float max, are added, causing an overflow.
If floating point exceptions are enabled, the application will be terminated.
In the enc_ma.cc code:
196 float lcost = std::numeric_limits<float>::max();
197 float rcost = std::numeric_limits<float>::max();
198 Predictor lpred = Predictor::Zero;
199 Predictor rpred = Predictor::Zero;
200 float Cost() const { return lcost + rcost; }
Calling Cost() can (and in practice will) add FLT_MAX to FLT_MAX.
Thread 1 "imageinout_test" received signal SIGFPE, Arithmetic exception.
0x00007ffff61c7291 in jxl::N_AVX2::FindBestSplit(jxl::TreeSamples&, float, std::vector<jxl::ModularMultiplierInfo, std::allocator<jxl::ModularMultiplierInfo> > const&, std::array<std::array<unsigned int, 2ul>, 2ul>, float, std::vector<jxl::PropertyDecisionNode, std::allocator<jxl::PropertyDecisionNode> >*)::SplitInfo::Cost() const
(this=0x7fffffff8870) at /home/stolk/src/libjxl/lib/jxl/modular/encoding/enc_ma.cc:200