Thumbnails: Add panic handler for unexpected image encoding errors #3858

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-10-31 14:37:47 +01:00
parent eae09353f2
commit d0ea838b37
2 changed files with 18 additions and 0 deletions

View file

@ -1,8 +1,10 @@
package thumb
import (
"fmt"
"image"
"path/filepath"
"runtime/debug"
"github.com/disintegration/imaging"
@ -12,6 +14,13 @@ import (
// Jpeg converts an image to JPEG, saves it, and returns it.
func Jpeg(srcFile, jpgFile string, orientation int) (img image.Image, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("jpeg: %s (panic)\nstack: %s", r, debug.Stack())
log.Error(err)
}
}()
// Resolve symlinks.
if srcFile, err = fs.Resolve(srcFile); err != nil {
log.Debugf("jpeg: %s in %s (resolve filename)", err, clean.Log(srcFile))

View file

@ -1,9 +1,11 @@
package thumb
import (
"fmt"
"image"
"image/png"
"path/filepath"
"runtime/debug"
"github.com/disintegration/imaging"
@ -13,6 +15,13 @@ import (
// Png converts an image to PNG, saves it, and returns it.
func Png(srcFile, pngFile string, orientation int) (img image.Image, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("png: %s (panic)\nstack: %s", r, debug.Stack())
log.Error(err)
}
}()
// Resolve symlinks.
if srcFile, err = fs.Resolve(srcFile); err != nil {
log.Debugf("png: %s in %s (resolve filename)", err, clean.Log(srcFile))