logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: ccbbee7963c8d67b99a44849000f7ac7d6b19109
parent 801a9367d00c0e036d1c157d6ca5c4e46bd0d95f
Author: lain <lain@soykaf.club>
Date:   Sun, 30 Jun 2024 09:28:17 +0000

Merge branch 'exif' into 'develop'

Ensure StripLocation works for PNGs

See merge request pleroma/pleroma!4167

Diffstat:

M.gitignore2+-
Achangelog.d/4167-strip-gps-info-in-png.fix1+
Mlib/pleroma/upload/filter/exiftool/strip_location.ex4+++-
Atest/fixtures/DSCN0010.png0
Mtest/pleroma/upload/filter/exiftool/strip_location_test.exs44+++++++++++++++++++++++---------------------
5 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -6,7 +6,7 @@ /test/instance /test/uploads /.elixir_ls -/test/fixtures/DSCN0010_tmp.jpg +/test/fixtures/DSCN0010_tmp* /test/fixtures/test_tmp.txt /test/fixtures/image_tmp.jpg /test/tmp/ diff --git a/changelog.d/4167-strip-gps-info-in-png.fix b/changelog.d/4167-strip-gps-info-in-png.fix @@ -0,0 +1 @@ +Ensure that StripLocation actually removes everything resembling GPS data from PNGs diff --git a/lib/pleroma/upload/filter/exiftool/strip_location.ex b/lib/pleroma/upload/filter/exiftool/strip_location.ex @@ -16,7 +16,9 @@ defmodule Pleroma.Upload.Filter.Exiftool.StripLocation do def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do try do - case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", file], parallelism: true) do + case System.cmd("exiftool", ["-overwrite_original", "-gps:all=", "-png:all=", file], + parallelism: true + ) do {_response, 0} -> {:ok, :filtered} {error, 1} -> {:error, error} end diff --git a/test/fixtures/DSCN0010.png b/test/fixtures/DSCN0010.png Binary files differ. diff --git a/test/pleroma/upload/filter/exiftool/strip_location_test.exs b/test/pleroma/upload/filter/exiftool/strip_location_test.exs @@ -9,29 +9,31 @@ defmodule Pleroma.Upload.Filter.Exiftool.StripLocationTest do test "apply exiftool filter" do assert Pleroma.Utils.command_available?("exiftool") - File.cp!( - "test/fixtures/DSCN0010.jpg", - "test/fixtures/DSCN0010_tmp.jpg" - ) - - upload = %Pleroma.Upload{ - name: "image_with_GPS_data.jpg", - content_type: "image/jpeg", - path: Path.absname("test/fixtures/DSCN0010.jpg"), - tempfile: Path.absname("test/fixtures/DSCN0010_tmp.jpg") - } - - assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered} - - {exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.jpg"]) - {exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.jpg"]) - - refute exif_original == exif_filtered - assert String.match?(exif_original, ~r/GPS/) - refute String.match?(exif_filtered, ~r/GPS/) + ~w{jpg png} + |> Enum.map(fn type -> + File.cp!( + "test/fixtures/DSCN0010.#{type}", + "test/fixtures/DSCN0010_tmp.#{type}" + ) + + upload = %Pleroma.Upload{ + name: "image_with_GPS_data.#{type}", + content_type: "image/jpeg", + path: Path.absname("test/fixtures/DSCN0010.#{type}"), + tempfile: Path.absname("test/fixtures/DSCN0010_tmp.#{type}") + } + + assert Filter.Exiftool.StripLocation.filter(upload) == {:ok, :filtered} + + {exif_original, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010.#{type}"]) + {exif_filtered, 0} = System.cmd("exiftool", ["test/fixtures/DSCN0010_tmp.#{type}"]) + + assert String.match?(exif_original, ~r/GPS/) + refute String.match?(exif_filtered, ~r/GPS/) + end) end - test "verify webp, heic, svg files are skipped" do + test "verify webp, heic, svg files are skipped" do uploads = ~w{webp heic svg svg+xml} |> Enum.map(fn type ->