Skip to content

Commit 83139c0

Browse files
committed
Check pointer size manually
1 parent 751fe8c commit 83139c0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/vips/image.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def self.p2str(pointer)
7878
class Image < Vips::Object
7979
alias_method :parent_get_typeof, :get_typeof
8080

81+
# FFI sets a pointer's size to this magic value if the size of the memory
82+
# chunk the pointer points to is unknown to FFI.
83+
UNKNOWN_POINTER_SIZE = FFI::Pointer.new(1).size
84+
private_constant :UNKNOWN_POINTER_SIZE
85+
8186
private
8287

8388
# the layout of the VipsImage struct
@@ -367,7 +372,9 @@ def self.new_from_memory data, width, height, bands, format
367372
# A pointer needs to know about the size of the memory it points to.
368373
# If you have an address-only pointer, use the .slice method to wrap
369374
# the pointer in a size aware pointer.
370-
raise Vips::Error, "pointer has no size limit" unless data.size_limit?
375+
if data.size == UNKNOWN_POINTER_SIZE
376+
raise Vips::Error, "size of memory is unknown"
377+
end
371378
size = data.size
372379
else
373380
size = data.bytesize
@@ -401,7 +408,9 @@ def self.new_from_memory_copy data, width, height, bands, format
401408
format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format
402409

403410
if data.is_a?(FFI::Pointer)
404-
raise Vips::Error, "pointer has no size limit" unless data.size_limit?
411+
if data.size == UNKNOWN_POINTER_SIZE
412+
raise Vips::Error, "size of memory is unknown"
413+
end
405414
size = data.size
406415
else
407416
size = data.bytesize

0 commit comments

Comments
 (0)