From 6cfc025f892b4f7619e5f18f1101931daa42e747 Mon Sep 17 00:00:00 2001 From: ChandanChainani Date: Tue, 4 Oct 2022 22:17:14 +0530 Subject: [PATCH] Fix panic on invalid file URI #3275 --- storage/repository/parse.go | 15 +++++++++------ theme/json_test.go | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/storage/repository/parse.go b/storage/repository/parse.go index 657020db41..78aaef5be0 100644 --- a/storage/repository/parse.go +++ b/storage/repository/parse.go @@ -59,13 +59,16 @@ func ParseURI(s string) (fyne.URI, error) { // we should punt this to whoever generated the URI in the // first place? - path := s[5:] // everything after file: - if len(path) > 2 && path[:2] == "//" { - path = path[2:] + if len(s) > 5 { + path := s[5:] // everything after file: + if len(path) > 2 && path[:2] == "//" { + path = path[2:] + } + + // Windows files can break authority checks, so just return the parsed file URI + return NewFileURI(path), nil } - - // Windows files can break authority checks, so just return the parsed file URI - return NewFileURI(path), nil + return nil, errors.New("not a valid URI") } repo, err := ForScheme(scheme) diff --git a/theme/json_test.go b/theme/json_test.go index 59c676be5d..5aea3999b3 100644 --- a/theme/json_test.go +++ b/theme/json_test.go @@ -28,6 +28,26 @@ func TestFromJSON(t *testing.T) { assert.Equal(t, float32(5), th.Size(SizeNameInlineIcon)) assert.Equal(t, "NotoMono-Regular.ttf", th.Font(fyne.TextStyle{Monospace: true}).Name()) assert.Equal(t, "cancel_Paths.svg", th.Icon(IconNameCancel).Name()) + + th, err = FromJSON(`{ +"Fonts":{"monospace":"file"} + }0000{ +"Fonts":{"monospace":"file"} + }0000{ +"Fonts":{"monospace":"file"} + }0000{ +"Fonts":{"monospace":"file"} + }0000{ +"Fonts":{"monospace":"file"} + }0000{ +"Fonts":{"monospace":"file"} + }0000{ +"Fonts":{"monospace":"file"} + }0000{ +"F + `) + assert.Nil(t, err) + th.Font(fyne.TextStyle{Monospace: true}).Name() } func TestFromTOML_Resource(t *testing.T) {