mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-25 09:34:16 -05:00
36bc90e8aa
The Blurhash library used by Mastodon requires an input encoded as 24 bits raw RGB data. The conversion to raw RGB using Imagemagick did not previously specify the desired bit depth. In some situations, this leads Imagemagick to output in a pixel format using less bpp than expected. This then manifested as segfaults of the Sidekiq process due to out-of-bounds read, or potentially a (highly noisy) memory infoleak. Fixes #19235.
17 lines
515 B
Ruby
17 lines
515 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Paperclip
|
|
class BlurhashTranscoder < Paperclip::Processor
|
|
def make
|
|
return @file unless options[:style] == :small || options[:blurhash]
|
|
|
|
pixels = convert(':source -depth 8 RGB:-', source: File.expand_path(@file.path)).unpack('C*')
|
|
geometry = options.fetch(:file_geometry_parser).from_file(@file)
|
|
|
|
attachment.instance.blurhash = Blurhash.encode(geometry.width, geometry.height, pixels, **(options[:blurhash] || {}))
|
|
|
|
@file
|
|
end
|
|
end
|
|
end
|