-
Notifications
You must be signed in to change notification settings - Fork 79
Limiting resources
Janko Marohnić edited this page Mar 27, 2018
·
4 revisions
When processing images that were uploaded by users, it can be useful to limit the amount of resources your imaging library is allowed to use for processing. This can also help prevent certain vectors of attack.
Resource limits for ImageMagick can be set either via environment variables or the -limit
command-line option. For the latter you can use ImageProcessing::MiniMagick#limits
:
ImageProcessing::MiniMagick
.limits(memory: "50MiB", width: "10MP", time: 30)
.resize_to_limit(400, 400)
.call(image)
# convert -limit memory 50MiB -limit width 10MP -limit time 30 input.jpg ... output.jpg
For more about ImageMagick's use of resources, see the Architecture page.
Libvips automatically caches results of operations to speed up overall processing. By default the last 1,000 operations are cached. You can control the cache via vips_cache_set_max()
, vips_cache_set_max_mem()
and vips_cache_set_max_files()
:
Vips.vips_cache_set_max 500 # up to 500 last operations
Vips.vips_cache_set_max_mem 100*1024*1024 # up to 100MB of data
Vips.vips_cache_set_max_files 500 # up to 500 tracked files