From 3a44dc46f2871ab8b4fdeb8c1f05eb2483e1a4d9 Mon Sep 17 00:00:00 2001
From: Travis Ralston <travpc@gmail.com>
Date: Sat, 15 Aug 2020 11:53:50 -0600
Subject: [PATCH] Handle orientation of zero as no orientation

---
 CHANGELOG.md           | 4 ++++
 util/util_exif/exif.go | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ebe6b7c4..266922ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 * Added a new tool, `export_synapse_for_import`, which can be used to do an offline import from Synapse.
   * After running this tool, use the `gdpr_import` tool to bring the export into the media repo.
 
+### Fixed
+
+* Fixed thumbnails for invalid JPEGs.
+
 ## [1.2.0] - August 2nd, 2020
 
 ### Upgrade notes
diff --git a/util/util_exif/exif.go b/util/util_exif/exif.go
index e3afe8f3..948da502 100644
--- a/util/util_exif/exif.go
+++ b/util/util_exif/exif.go
@@ -40,6 +40,11 @@ func GetExifOrientation(img io.ReadCloser) (*ExifOrientation, error) {
 		return nil, errors.New("exif: error parsing orientation: " + err.Error())
 	}
 
+	// Some devices produce invalid exif data when they intend to mean "no orientation"
+	if orientation == 0 {
+		return nil, nil
+	}
+
 	if orientation < 1 || orientation > 8 {
 		return nil, errors.New(fmt.Sprintf("orientation out of range: %d", orientation))
 	}
-- 
GitLab