Skip to content

undefined behavior in XYZ2Lab: float-to-int overflow #4961

@dloebl

Description

@dloebl

Found with #4957

Reproducer

libvips must be built with UBSAN:

meson setup build -Db_sanitize=undefined
meson compile -C build

And then the following colourspace command crashes:

./build/tools/vips black /tmp/rgb.v 8 8 --bands 3
./build/tools/vips linear /tmp/rgb.v /tmp/rgb255.v 0 255
./build/tools/vips colourspace /tmp/rgb255.v /tmp/out.v lab --source-space oklab

UBSAN output

../libvips/colour/XYZ2Lab.c:123:6: runtime error: 8.38422e+12 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../libvips/colour/XYZ2Lab.c:123:6 
../libvips/colour/XYZ2Lab.c:123:6: runtime error: 8.38422e+12 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../libvips/colour/XYZ2Lab.c:123:6 
../libvips/colour/XYZ2Lab.c:127:6: runtime error: 7.81401e+11 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../libvips/colour/XYZ2Lab.c:127:6 
../libvips/colour/XYZ2Lab.c:127:6: runtime error: 7.81401e+11 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../libvips/colour/XYZ2Lab.c:127:6 
../libvips/colour/XYZ2Lab.c:131:6: runtime error: -9.88714e+11 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../libvips/colour/XYZ2Lab.c:131:6 
../libvips/colour/XYZ2Lab.c:131:6: runtime error: -9.88714e+11 is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../libvips/colour/XYZ2Lab.c:131:6 

Environment

  • libvips master (4f2389d)
  • macOS, M3 Pro (aarch64)
  • Highway enabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions