Skip to content

Commit

Permalink
blurhash_transcoder: prevent out-of-bound reads with <8bpp images (ma…
Browse files Browse the repository at this point in the history
…stodon#20388)

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 mastodon#19235.
  • Loading branch information
delroth authored and atsu1125 committed Nov 14, 2022
1 parent 9a54db7 commit 2954a35
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip/blurhash_transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BlurhashTranscoder < Paperclip::Processor
def make
return @file unless options[:style] == :small || options[:blurhash]

pixels = convert(':source RGB:-', source: File.expand_path(@file.path)).unpack('C*')
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] || {}))
Expand Down

0 comments on commit 2954a35

Please sign in to comment.