Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating Point Domain Error triggered by IdentifyBuiltinColorSpace() #2066

Open
stolk opened this issue Sep 30, 2024 · 0 comments · May be fixed by #2067
Open

Floating Point Domain Error triggered by IdentifyBuiltinColorSpace() #2066

stolk opened this issue Sep 30, 2024 · 0 comments · May be fixed by #2067

Comments

@stolk
Copy link

stolk commented Sep 30, 2024

IdentifyBuiltinColorSpace() applies transformations on pixel values that can leave the pixel value containing negative values.

Subsequently, when a gamma curve is applied in OpenColorIO_v2_4dev::GammaMoncurveOpCPURev::apply() the powf() function is called with a negative base and a fractional power, which causes a domain error.

This leads to a SIGFPE and will abort applications that have floating point exceptions enabled.

#0  0x00007ffff6fb9c4e in __math_invalidf (x=-0.0485877097) at ../sysdeps/ieee754/flt-32/math_errf.c:80
#1  0x00007ffff50f6271 in std::pow (__x=-0.0485877097, __y=0.416666657) at /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/cmath:373
#2  0x00007ffff535681f in OpenColorIO_v2_4dev::GammaMoncurveOpCPURev::apply (this=0x555556e01fa0, inImg=0x555556e2e190, outImg=0x555556e2e190, numPixels=5)
    at /home/stolk/src/OpenColorIO/src/OpenColorIO/ops/gamma/GammaOpCPU.cpp:634
#3  0x00007ffff5583874 in OpenColorIO_v2_4dev::GenericScanlineHelper<float, float>::finishRGBAScanline (this=0x555556ebe780)
    at /home/stolk/src/OpenColorIO/src/OpenColorIO/ScanlineHelper.cpp:164
#4  0x00007ffff517e898 in OpenColorIO_v2_4dev::CPUProcessor::Impl::apply (this=0x555556e0be20, srcImgDesc=..., dstImgDesc=...)
    at /home/stolk/src/OpenColorIO/src/OpenColorIO/CPUProcessor.cpp:431
#5  0x00007ffff517edbd in OpenColorIO_v2_4dev::CPUProcessor::apply (this=0x555556e7b3b0, srcImgDesc=..., dstImgDesc=...)
    at /home/stolk/src/OpenColorIO/src/OpenColorIO/CPUProcessor.cpp:543
#6  0x00007ffff516dec3 in OpenColorIO_v2_4dev::ConfigUtils::isIdentityTransform (
    proc=std::shared_ptr<const OpenColorIO_v2_4dev::Processor> (use count 1, weak count 0) = {...}, RGBAvals=std::vector of length 20, capacity 20 = {...}, 
    absTolerance=0.00100000005) at /home/stolk/src/OpenColorIO/src/OpenColorIO/ConfigUtils.cpp:262
#7  0x00007ffff51704db in OpenColorIO_v2_4dev::ConfigUtils::IdentifyBuiltinColorSpace (
    srcConfig=std::shared_ptr<const OpenColorIO_v2_4dev::Config> (use count 2, weak count 0) = {...}, 
    builtinConfig=std::shared_ptr<const OpenColorIO_v2_4dev::Config> (use count 2, weak count 0) = {...}, builtinColorSpaceName=0x7ffff7bef833 "srgb_tx")
    at /home/stolk/src/OpenColorIO/src/OpenColorIO/ConfigUtils.cpp:826
#8  0x00007ffff513f025 in OpenColorIO_v2_4dev::Config::IdentifyBuiltinColorSpace (
    srcConfig=std::shared_ptr<const OpenColorIO_v2_4dev::Config> (use count 2, weak count 0) = {...}, 
    builtinConfig=std::shared_ptr<const OpenColorIO_v2_4dev::Config> (use count 2, weak count 0) = {...}, builtinColorSpaceName=0x7ffff7bef833 "srgb_tx")
    at /home/stolk/src/OpenColorIO/src/OpenColorIO/Config.cpp:2911
#9  0x00007ffff79b3a38 in OpenImageIO_v2_6_7::ColorConfig::Impl::IdentifyBuiltinColorSpace (this=0x555556e00de0, name=0x7ffff7bef833 "srgb_tx")
    at /home/stolk/src/OpenImageIO/src/libOpenImageIO/color_ocio.cpp:770
#10 0x00007ffff79b2746 in OpenImageIO_v2_6_7::ColorConfig::Impl::identify_builtin_equivalents (this=0x555556e00de0)
    at /home/stolk/src/OpenImageIO/src/libOpenImageIO/color_ocio.cpp:729
#11 0x00007ffff79b4743 in OpenImageIO_v2_6_7::ColorConfig::Impl::init (this=0x555556e00de0, filename=...)
    at /home/stolk/src/OpenImageIO/src/libOpenImageIO/color_ocio.cpp:835
#12 0x00007ffff79b3d1e in OpenImageIO_v2_6_7::ColorConfig::reset (this=0x7ffff7f975e0 <OpenImageIO_v2_6_7::ColorConfig::default_colorconfig()::config>, filename=...)
    at /home/stolk/src/OpenImageIO/src/libOpenImageIO/color_ocio.cpp:882
#13 0x00007ffff79b3ac7 in OpenImageIO_v2_6_7::ColorConfig::ColorConfig (this=0x7ffff7f975e0 <OpenImageIO_v2_6_7::ColorConfig::default_colorconfig()::config>, 
    filename=...) at /home/stolk/src/OpenImageIO/src/libOpenImageIO/color_ocio.cpp:780
#14 0x00007ffff79aff2e in OpenImageIO_v2_6_7::ColorConfig::default_colorconfig () at /home/stolk/src/OpenImageIO/src/libOpenImageIO/color_ocio.cpp:67
#15 0x00007ffff7b223a9 in OpenImageIO_v2_6_7::PNG_pvt::write_info[abi:cxx11](png_struct_def*&, png_info_def*&, int&, OpenImageIO_v2_6_7::ImageSpec&, std::vector<png_text_struct, std::allocator<png_text_struct> >&, bool&, bool&, float&) (sp=@0x555556e04268: 0x555556e8b260, ip=@0x555556e04270: 0x555556ddda10, 
    color_type=@0x555556e0427c: 6, spec=..., text=std::vector of length 0, capacity 0, convert_alpha=@0x555556e04280: true, srgb=@0x555556e04282: false, 
    gamma=@0x555556e04284: 1) at /home/stolk/src/OpenImageIO/src/png.imageio/png_pvt.h:607
#16 0x00007ffff7b7746e in OpenImageIO_v2_6_7::PNGOutput::open (this=0x555556e04190, name="imageinout_test-png.png", userspec=..., 
    mode=OpenImageIO_v2_6_7::ImageOutput::Create) at /home/stolk/src/OpenImageIO/src/png.imageio/pngoutput.cpp:218
#17 0x0000555555564d59 in checked_write (out=0x555556e04190, filename=..., spec=..., type=..., data=0x555556de6e20, do_asserts=true, errmsg=0x0, ioproxy=0x0)
    at /home/stolk/src/OpenImageIO/src/libOpenImageIO/imageinout_test.cpp:124
#18 0x0000555555563728 in test_all_formats () at /home/stolk/src/OpenImageIO/src/libOpenImageIO/imageinout_test.cpp:393
#19 0x0000555555562db6 in main (argc=2, argv=0x7fffffffdcd8) at /home/stolk/src/OpenImageIO/src/libOpenImageIO/imageinout_test.cpp:550

From the powf() manual page:

If x is a finite value less than 0, and y is a finite noninteger, a domain error occurs, and a NaN is returned.

OpenColorIO should not be calling powf() on negative values.

stolk added a commit to stolk/OpenColorIO that referenced this issue Sep 30, 2024
This change prevents calling powf(x,y) with negative x.

The SIMD versions using ssePower() already seem to be resistent to
negative pixel values, but the scalar version was not.

This would cause a SIGFPE on apps that have floating point exceptions
enabled.

FIXES: AcademySoftwareFoundation#2066

Signed-off-by: Bram Stolk <[email protected]>
@stolk stolk linked a pull request Sep 30, 2024 that will close this issue
stolk added a commit to stolk/OpenColorIO that referenced this issue Sep 30, 2024
This change prevents calling powf(x,y) with negative x.

The SIMD versions using ssePower() already seem to be resistent to
negative pixel values, but the scalar version was not.

This would cause a SIGFPE on apps that have floating point exceptions
enabled.

FIXES: AcademySoftwareFoundation#2066

Signed-off-by: Bram Stolk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant