From 25e88bb1fca7b6a641084bc1a1812b3279e58075 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Sat, 21 Nov 2020 23:43:53 +0100 Subject: [PATCH] Use mutex when extracting Exif metadata #600 Signed-off-by: Michael Mayer --- internal/meta/exif.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/meta/exif.go b/internal/meta/exif.go index c4f49c8e1..bb0df687b 100644 --- a/internal/meta/exif.go +++ b/internal/meta/exif.go @@ -7,6 +7,7 @@ import ( "runtime/debug" "strconv" "strings" + "sync" "time" "github.com/dsoprea/go-exif/v3" @@ -19,6 +20,7 @@ import ( var exifIfdMapping *exifcommon.IfdMapping var exifTagIndex = exif.NewTagIndex() +var exifMutex = sync.Mutex{} const DateTimeZero = "0000:00:00 00:00:00" @@ -44,6 +46,9 @@ func Exif(fileName string, fileType fs.FileType) (data Data, err error) { // Exif parses an image file for Exif meta data and returns as Data struct. func (data *Data) Exif(fileName string, fileType fs.FileType) (err error) { + exifMutex.Lock() + defer exifMutex.Unlock() + defer func() { if e := recover(); e != nil { err = fmt.Errorf("metadata: %s in %s (exif panic)\nstack: %s", e, txt.Quote(filepath.Base(fileName)), debug.Stack())