Recover from SIGSEGVs in taglib's code

This commit is contained in:
Deluan
2021-11-20 12:33:06 -05:00
parent cbeaadf8e2
commit 0714f08274
@@ -12,6 +12,7 @@ package taglib
import "C" import "C"
import ( import (
"fmt" "fmt"
"runtime/debug"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@@ -21,12 +22,15 @@ import (
) )
func Read(filename string) (tags map[string][]string, err error) { func Read(filename string) (tags map[string][]string, err error) {
// Do not crash on failures in the C code/library
debug.SetPanicOnFault(true)
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Error("TagLib: recovered from panic when reading tags", "file", filename, "error", r) log.Error("TagLib: recovered from panic when reading tags", "file", filename, "error", r)
err = fmt.Errorf("TagLib: recovered from panic: %s", r) err = fmt.Errorf("TagLib: recovered from panic: %s", r)
} }
}() }()
fp := getFilename(filename) fp := getFilename(filename)
defer C.free(unsafe.Pointer(fp)) defer C.free(unsafe.Pointer(fp))
id, m := newMap() id, m := newMap()