diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eb1e61d..686cbe92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +* improve NULL pointer handling [dloebl] + ## Version 2.2.4 (2025-06-05) * fix write to target test with libvips 8.17 [jcupitt] diff --git a/VERSION b/VERSION index 530cdd91..21bb5e15 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.4 +2.2.5 diff --git a/lib/vips/image.rb b/lib/vips/image.rb index ea8b1af5..9ee303ac 100644 --- a/lib/vips/image.rb +++ b/lib/vips/image.rb @@ -471,9 +471,10 @@ def self.new_from_source source, option_string, **opts def self.matrix_from_array width, height, array ptr = FFI::MemoryPointer.new :double, array.length ptr.write_array_of_double array - image = Vips.vips_image_new_matrix_from_array width, height, + img_ptr = Vips.vips_image_new_matrix_from_array width, height, ptr, array.length - Vips::Image.new image + raise Vips::Error if img_ptr.null? + Vips::Image.new img_ptr end # Create a new Image from a 1D or 2D array. A 1D array becomes an @@ -534,7 +535,6 @@ def self.new_from_array array, scale = 1, offset = 0 end image = Vips::Image.matrix_from_array width, height, array - raise Vips::Error if image.nil? image.mutate do |mutable| # be careful to set them as double @@ -700,7 +700,7 @@ def write_to_target target, format_string, **opts def write_to_memory len = Vips::SizeStruct.new ptr = Vips.vips_image_write_to_memory self, len - raise Vips::Error if ptr.nil? + raise Vips::Error if ptr.null? # wrap up as an autopointer ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE) diff --git a/lib/vips/interpolate.rb b/lib/vips/interpolate.rb index e31450a1..891b1e59 100644 --- a/lib/vips/interpolate.rb +++ b/lib/vips/interpolate.rb @@ -50,7 +50,7 @@ class ManagedStruct < Vips::Object::ManagedStruct def initialize name name = name.to_s if name.is_a? Symbol pointer = Vips.vips_interpolate_new name - raise Vips::Error if pointer.nil? + raise Vips::Error if pointer.null? super(pointer) end diff --git a/lib/vips/version.rb b/lib/vips/version.rb index e00f5c8f..c7cc34f8 100644 --- a/lib/vips/version.rb +++ b/lib/vips/version.rb @@ -1,3 +1,3 @@ module Vips - VERSION = "2.2.4" + VERSION = "2.2.5" end diff --git a/spec/image_spec.rb b/spec/image_spec.rb index 38fdb29a..69ff2c32 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -76,6 +76,11 @@ expect(x.avg).to eq(128) end + it "will raise VipsError for invalid image files" do + img = Vips::Image.new_from_file simg("coffee.gif") + expect { img.write_to_memory }.to raise_exception(Vips::Error) + end + it "throws an error when trying to load an image from memory with unknown size" do data = FFI::Pointer.new(1) expect { Vips::Image.new_from_memory(data, 16, 16, 1, :uchar) }.to raise_error(Vips::Error) diff --git a/spec/samples/coffee.gif b/spec/samples/coffee.gif new file mode 100644 index 00000000..bf794f61 Binary files /dev/null and b/spec/samples/coffee.gif differ diff --git a/spec/vips_spec.rb b/spec/vips_spec.rb index c569071b..3b8c407d 100644 --- a/spec/vips_spec.rb +++ b/spec/vips_spec.rb @@ -193,5 +193,9 @@ expect { black.crop(10, 10, 1, 1) }.to raise_exception(Vips::Error) end + + it "can throw errors for bad interpolations" do + expect { Vips::Interpolate.new "banana" }.to raise_exception(Vips::Error) + end end end