From 5d8d22a52d422d5e755d9abf790cab6850ca5eec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20Walld=C3=A9n?= <jonasw@roxen.com>
Date: Thu, 20 Aug 2020 12:37:47 +0200
Subject: [PATCH] Fix broken detection of EXIF section when multiple 0xE1 app
 markers were present in the file.

---
 lib/modules/Standards.pmod/EXIF.pmod | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/modules/Standards.pmod/EXIF.pmod b/lib/modules/Standards.pmod/EXIF.pmod
index 60ed97db36..8a554a7a95 100644
--- a/lib/modules/Standards.pmod/EXIF.pmod
+++ b/lib/modules/Standards.pmod/EXIF.pmod
@@ -1167,10 +1167,15 @@ mapping(string:mixed) get_properties(Stdio.File file, void|mapping tags)
     default:
       int size;
       sscanf(file->read(2), "%2c", size);
-      if( marker==0xe1 && file->read(6) == "Exif\0\0" )
-      {
-        file = Stdio.FakeFile(file->read(size-2-6));
-        break loop;
+      if (marker == 0xe1) {
+        //  There could be other app sections tagged with 0xE1, not just EXIF
+        if (file->read(6) == "Exif\0\0") {
+          file = Stdio.FakeFile(file->read(size - 2 - 6));
+          break loop;
+        } else {
+          //  Undo last read
+          file->seek(file->tell() - 6);
+        }
       }
       file->read(size-2);
       continue;
-- 
GitLab