Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions lib/vips/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,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
Expand Down Expand Up @@ -700,7 +699,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)
Expand Down
2 changes: 1 addition & 1 deletion lib/vips/interpolate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file added spec/samples/coffee.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions spec/vips_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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