From d74bfdee4317abbb12af08262b1d3e2fbeb4fb94 Mon Sep 17 00:00:00 2001 From: anon <38473290+tetsugakusha256@users.noreply.github.com> Date: Fri, 7 Aug 2026 18:28:37 +0900 Subject: [PATCH] fix: don't require FFD9 as literal last bytes for JPEG detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Files with data appended after the JPEG EOI marker (Google/Samsung Motion Photos, etc.) were being rejected by detect_format/is_image since has_jpeg_end_signature required FFD9 to be the file's final two bytes. These are valid, fully renderable JPEGs — ImageMagick decodes them fine, it just stops at EOI and ignores trailing data. --- lua/image/utils/magic.lua | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lua/image/utils/magic.lua b/lua/image/utils/magic.lua index 077102e..b53ea10 100644 --- a/lua/image/utils/magic.lua +++ b/lua/image/utils/magic.lua @@ -24,15 +24,6 @@ local function read_file_header(file, num_bytes) return content and { content:byte(1, #content) } or nil end -local function has_jpeg_end_signature(file) - if not file then return false end - local size = file:seek("end") - if size < 2 then return false end - file:seek("set", size - 2) - local end_signature = file:read(2) - return end_signature == "\xFF\xD9", nil -end - local function check_signature_match(header, format, signature) local bytes = { signature:byte(1, #signature) } local match = true @@ -70,14 +61,8 @@ M.detect_format = function(path) for format, signature in pairs(image_signatures) do if check_signature_match(header, format, signature) then - if format == "jpeg" then - local is_jpeg = has_jpeg_end_signature(file) - file:close() - return is_jpeg and format or nil - else - file:close() - return format - end + file:close() + return format end end