You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Image#copy_memory returns an image wrapping NULL when libvips fails, and the next call segfaults #442
When vips_image_copy_memory() fails (for example because the source image cannot be decoded), it returns NULL. Vips::Image#copy_memory wraps that pointer in a Vips::Image without checking it, so instead of raising Vips::Error, the call returns an object whose pointer is NULL. The next operation on that object dereferences it and crashes the whole Ruby process with a segmentation fault, which cannot be rescued.
Versions
ruby-vips 2.3.0 (also master as of 2026-10-15)
libvips 8.16.1
Ruby 4.0.7 (aarch64-linux, Debian, in Docker)
also returns NULL with libvips 8.18.7 / Ruby 4.0.6 on macOS arm64
Reproduction
require"vips"# A valid JPEG cut in half: the header is intact, so the load itself succeeds# lazily, and decoding fails only when the pixels are computed.jpeg=Vips::Image.black(256,256).add(128).cast(:uchar).jpegsave_bufferbroken=jpeg.byteslice(0,jpeg.bytesize / 2)image=Vips::Image.new_from_buffer(broken,"",fail_on: :error)copy=image.copy_memory# libvips fails and returns NULLpcopy.class# => Vips::Imagepcopy.ptr.null?# => truecopy.width# segfault
Output:
(process:1): VIPS-WARNING **: error in tile 0 x 40
Vips::Image
true
/usr/local/bundle/ruby/4.0.0/gems/ruby-vips-2.3.0/lib/vips/image.rb:891: [BUG] Segmentation fault at 0x0000000000000050
ruby 4.0.7 (2026-09-15 revision 229531a6cf) +YJIT +PRISM [aarch64-linux]
-- Ruby level backtrace information ----------------------------------------
repro.rb:12:in '<main>'
.../ruby-vips-2.3.0/lib/vips/image.rb:891:in 'width'
.../ruby-vips-2.3.0/lib/vips/image.rb:891:in 'vips_image_get_width'
Expected behaviour
copy_memory raises Vips::Error with the libvips error message (here VipsJpeg: premature end of JPEG image), as other methods do when libvips fails.
Activity