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
1 changed files with 4 additions and 0 deletions

View File

@ -12,6 +12,7 @@ package taglib
import "C"
import (
"fmt"
"runtime/debug"
"strconv"
"strings"
"sync"
@ -21,12 +22,15 @@ import (
)
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() {
if r := recover(); r != nil {
log.Error("TagLib: recovered from panic when reading tags", "file", filename, "error", r)
err = fmt.Errorf("TagLib: recovered from panic: %s", r)
}
}()
fp := getFilename(filename)
defer C.free(unsafe.Pointer(fp))
id, m := newMap()