From 0864d04c5c7d8425de479a1a03f8c6e360bac427 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Thu, 4 Sep 2025 11:23:05 +0200 Subject: [PATCH] internal/restic: Fix panic in ParseDuration Fixes #5485. Includes test case by @MichaelEischer. --- internal/restic/duration.go | 3 +-- internal/restic/duration_test.go | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/restic/duration.go b/internal/restic/duration.go index 831971fe0..6ab4c3c79 100644 --- a/internal/restic/duration.go +++ b/internal/restic/duration.go @@ -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 } diff --git a/internal/restic/duration_test.go b/internal/restic/duration_test.go index f03aa5553..c5f0390db 100644 --- a/internal/restic/duration_test.go +++ b/internal/restic/duration_test.go @@ -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 {