logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/
commit: a1f4da7ae2ed5d063b3d146f223a96b9db9bb505
parent 011d70df792fff9ecae8cc92728b45c026fe9be3
Author: lain <lain@soykaf.club>
Date:   Thu, 30 Jan 2025 09:19:59 +0000

Merge branch '3355-vips-blurhash' into 'develop'

AnalyzeMetadata: Don't crash on grayscale image blurhash

Closes #3355

See merge request pleroma/pleroma!4319

Diffstat:

Achangelog.d/vips-blurhash.fix1+
Mlib/pleroma/upload/filter/analyze_metadata.ex10+++++++---
Atest/fixtures/break_analyze.png0
Mtest/pleroma/upload/filter/analyze_metadata_test.exs14++++++++++++++
4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/changelog.d/vips-blurhash.fix b/changelog.d/vips-blurhash.fix @@ -0,0 +1 @@ +Fix blurhash generation crashes diff --git a/lib/pleroma/upload/filter/analyze_metadata.ex b/lib/pleroma/upload/filter/analyze_metadata.ex @@ -90,9 +90,13 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadata do {:ok, rgb} = if Image.has_alpha?(resized_image) do # remove alpha channel - resized_image - |> Operation.extract_band!(0, n: 3) - |> Image.write_to_binary() + case Operation.extract_band(resized_image, 0, n: 3) do + {:ok, data} -> + Image.write_to_binary(data) + + _ -> + Image.write_to_binary(resized_image) + end else Image.write_to_binary(resized_image) end diff --git a/test/fixtures/break_analyze.png b/test/fixtures/break_analyze.png Binary files differ. diff --git a/test/pleroma/upload/filter/analyze_metadata_test.exs b/test/pleroma/upload/filter/analyze_metadata_test.exs @@ -34,6 +34,20 @@ defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do assert meta.blurhash == "eXJi-E:SwCEm5rCmn$+YWYn+15K#5A$xxCi{SiV]s*W:Efa#s.jE-T" end + test "it gets dimensions for grayscale images" do + upload = %Pleroma.Upload{ + name: "break_analyze.png", + content_type: "image/png", + path: Path.absname("test/fixtures/break_analyze.png"), + tempfile: Path.absname("test/fixtures/break_analyze.png") + } + + {:ok, :filtered, meta} = AnalyzeMetadata.filter(upload) + + assert %{width: 1410, height: 2048} = meta + assert is_nil(meta.blurhash) + end + test "adds the dimensions for videos" do upload = %Pleroma.Upload{ name: "coolvideo.mp4",