From 07f27312fa05887a497e7c4443fcd3596b37148c Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Sun, 7 Apr 2024 10:16:55 -0700 Subject: [PATCH] x/model: copy text in UnmarshalText --- x/model/name.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/x/model/name.go b/x/model/name.go index 71bc1e08..147e2acc 100644 --- a/x/model/name.go +++ b/x/model/name.go @@ -11,7 +11,6 @@ import ( "slices" "strings" "sync" - "unsafe" "github.com/ollama/ollama/x/types/structs" ) @@ -333,14 +332,10 @@ func (r *Name) UnmarshalText(text []byte) error { // the immutability of the Name. return errors.New("model.Name: UnmarshalText on valid Name") } - // unsafeString is safe here because the contract of UnmarshalText - // that text belongs to us for the duration of the call. - *r = ParseName(unsafeString(text)) - return nil -} -func unsafeString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + // The contract of UnmarshalText is that we copy to keep the text. + *r = ParseName(string(text)) + return nil } // Complete reports whether the Name is fully qualified. That is it has a