Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/changelog.d/attachment-zero-size.fix b/changelog.d/attachment-zero-size.fix
new file mode 100644
index 000000000..dc42677c4
--- /dev/null
+++ b/changelog.d/attachment-zero-size.fix
@@ -0,0 +1 @@
+Do not crash when rendering attachments with zero width or height
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 4625be47c..6a5d627a5 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -675,7 +675,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render("attachment_meta.json", %{
attachment: %{"url" => [%{"width" => width, "height" => height} | _]}
})
- when is_integer(width) and is_integer(height) do
+ when is_integer(width) and is_integer(height) and width > 0 and height > 0 do
%{
original: %{
width: width,
diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs
index f7b815ed7..1a0d7a3ce 100644
--- a/test/pleroma/web/mastodon_api/views/status_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs
@@ -597,6 +597,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
end
describe "attachments" do
+ test "skips meta for zero dimensions" do
+ for {width, height} <- [{0, 0}, {200, 0}, {0, 100}] do
+ object = %{
+ "type" => "Image",
+ "url" => [
+ %{
+ "mediaType" => "image/png",
+ "href" => "someurl",
+ "width" => width,
+ "height" => height
+ }
+ ]
+ }
+
+ refute Map.has_key?(StatusView.render("attachment.json", %{attachment: object}), :meta)
+ end
+ end
+
test "Complete Mastodon style" do
object = %{
"type" => "Image",

File Metadata

Mime Type
text/x-diff
Expires
Thu, Oct 29, 8:00 AM (11 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1797753
Default Alt Text
(1 KB)

Event Timeline