#4961·libvips

undefined behavior in XYZ2Lab: float-to-int overflow

Author: dloeblCreated Mar 21, 2026Updated Mar 23, 2026
Labelsbug

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 (4f2389d2ae38438615aa2c39d4dd0488ccc4981e)
  • macOS, M3 Pro (aarch64)
  • Highway enabled