Skip to content

Commit

Permalink
Thumbnails: Add panic handler for unexpected image encoding errors #3858
Browse files Browse the repository at this point in the history


Signed-off-by: Michael Mayer <michael@photoprism.app>
  • Loading branch information
lastzero committed Oct 31, 2023
1 parent eae0935 commit d0ea838
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/thumb/jpeg.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package thumb

import (
"fmt"
"image"
"path/filepath"
"runtime/debug"

"github.com/disintegration/imaging"

Expand All @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions internal/thumb/png.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package thumb

import (
"fmt"
"image"
"image/png"
"path/filepath"
"runtime/debug"

"github.com/disintegration/imaging"

Expand All @@ -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))
Expand Down

0 comments on commit d0ea838

Please sign in to comment.