Merge pull request #5486 from greatroar/duration-panic

Avoid panic in duration parsing
This commit is contained in:
Michael Eischer
2025-09-06 18:32:36 +02:00
committed by GitHub
2 changed files with 5 additions and 2 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"strconv"
"strings"
"unicode"
"github.com/restic/restic/internal/errors"
)
@@ -52,7 +51,7 @@ func nextNumber(input string) (num int, rest string, err error) {
}
for i, s := range input {
if !unicode.IsNumber(s) {
if s < '0' || s > '9' {
rest = input[i:]
break
}

View File

@@ -37,6 +37,9 @@ func TestNextNumber(t *testing.T) {
{
input: "5d ", num: 5, rest: "d ",
},
{
input: "5", num: 5, rest: "",
},
}
for _, test := range tests {
@@ -78,6 +81,7 @@ func TestParseDuration(t *testing.T) {
{input: "2w", err: true},
{input: "1y4m3w1d", err: true},
{input: "s", err: true},
{input: "\xdf\x80", err: true}, // NKO DIGIT ZERO; we want ASCII digits
}
for _, test := range tests {