mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-30 09:57:57 -04:00
fix(backend): don't crash the whole process on an invalid cutstrings/extract_regex (#10855)
Finetune() compiled every model cutstrings/extract_regex entry via regexp.Compile
and called xlog.Fatal on failure, which terminates the entire local-ai process.
A single model config with an invalid regex (e.g. cutstrings: ["("]) turns one
/v1/chat/completions request into a process-level denial of service.
Log the compile error and skip the offending pattern instead. The mutex is
released before continuing, and skipping avoids dereferencing the nil regexp
that removing the fatal would otherwise leave behind.
Fixes #10843
Signed-off-by: Tai An <antai12232931@outlook.com>
This commit is contained in:
@@ -463,7 +463,9 @@ func Finetune(config config.ModelConfig, input, prediction string) string {
|
||||
if !ok {
|
||||
r, err := regexp.Compile(c)
|
||||
if err != nil {
|
||||
xlog.Fatal("failed to compile regex", "error", err)
|
||||
mu.Unlock()
|
||||
xlog.Error("failed to compile cutstrings regex, skipping", "error", err, "regex", c)
|
||||
continue
|
||||
}
|
||||
cutstrings[c] = r
|
||||
reg = cutstrings[c]
|
||||
@@ -480,7 +482,9 @@ func Finetune(config config.ModelConfig, input, prediction string) string {
|
||||
if !ok {
|
||||
regex, err := regexp.Compile(r)
|
||||
if err != nil {
|
||||
xlog.Fatal("failed to compile regex", "error", err)
|
||||
mu.Unlock()
|
||||
xlog.Error("failed to compile extract_regex regex, skipping", "error", err, "regex", r)
|
||||
continue
|
||||
}
|
||||
cutstrings[r] = regex
|
||||
reg = regex
|
||||
|
||||
Reference in New Issue
Block a user