api/view: handle explicitly zero dimensions in attachments

Some peertube videos are federated with explicitly zero dimensions
for their mp4 link leading to a division-by-zero exception here.
E.g.: https://spectra.video/videos/watch/66c12674-2013-47a4-9126-51ff8eb8d0a8
      (as of writing using peertube 8.1.1)

Reported by temp3 on IRC

(cherry picked from commit 6833281051aa86b3d82232be29497fed47bf5fb1)
This commit is contained in:
Oneric 2026-03-15 00:00:00 +00:00 • committed by Lain Soykaf
commit 9443aba06c
No known key found for this signature in database

View file

@ -675,7 +675,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render("attachment_meta.json", %{ def render("attachment_meta.json", %{
attachment: %{"url" => [%{"width" => width, "height" => height} | _]} 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: %{ original: %{
width: width, width: width,