Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6f54bbc

Browse files
author
Andrey Glushkov
committed
Add wrappers to vips_block_untrusted_set and vips_operation_block_set methods
Block/unblock all untrusted operations: ```ruby Vips.block_untrusted Vips.block_untrusted(false) ``` Block/unblock specific operations hierarchy: ```ruby Vips.block("VipsForeignLoad"); Vips.block("VipsForeignLoadJpeg", false) ```
1 parent cddd270 commit 6f54bbc

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

‎lib/vips/operation.rb‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ module Vips
1111
if at_least_libvips?(8, 13)
1212
attach_function :vips_block_untrusted_set, [:bool], :void
1313
attach_function :vips_operation_block_set, %i[string bool], :void
14+
15+
# Block/unblock all untrusted operations from running.
16+
# Use `vips -l` at the command-line to see the class hierarchy and which operations are marked as untrusted.
17+
def self.block_untrusted(enabled = true)
18+
vips_block_untrusted_set(enabled)
19+
end
20+
21+
# Block/unblock all operations in the libvips class hierarchy at specified *operation_name* and below.
22+
#
23+
# For example this will block all loaders except JPEG
24+
#
25+
# Vips.block("VipsForeignLoad");
26+
# Vips.block("VipsForeignLoadJpeg", false)
27+
#
28+
# Use `vips -l` at the command-line to see the class hierarchy.
29+
# This call does nothing if the named operation is not found.
30+
#
31+
def self.block(operation_name, enabled = true)
32+
vips_operation_block_set(operation_name, enabled)
33+
end
1434
end
1535

1636
private

‎spec/block_operations_spec.rb‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@
99
untrusted_image = svg_image # svgload operation is known as untrusted
1010

1111
# Block
12-
Vips.vips_block_untrusted_set(true)
12+
Vips.block_untrusted
1313
expect { Vips::Image.new_from_file(untrusted_image) }.to raise_error Vips::Error, /svgload/
1414

1515
# Unblock
16-
Vips.vips_block_untrusted_set(false)
16+
Vips.block_untrusted(false)
1717
expect { Vips::Image.new_from_file(untrusted_image) }.not_to raise_error
1818
end
1919
end
2020

2121
if has_jpeg? && has_svg?
2222
it "can block specific operations" do
2323
# Block all loaders except jpeg
24-
Vips.vips_operation_block_set("VipsForeignLoad",true)
25-
Vips.vips_operation_block_set("VipsForeignLoadJpeg", false)
24+
Vips.block("VipsForeignLoad")
25+
Vips.block("VipsForeignLoadJpeg", false)
2626
expect { Vips::Image.new_from_file(svg_image) }.to raise_error Vips::Error, /svgload/
2727
expect { Vips::Image.new_from_file(jpg_image) }.not_to raise_error
2828

2929
# Unblock all loaders
30-
Vips.vips_operation_block_set("VipsForeignLoad", false)
30+
Vips.block("VipsForeignLoad", false)
3131
expect { Vips::Image.new_from_file(svg_image) }.not_to raise_error
3232
end
3333
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /