Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
400056e1
Unverified
Commit
400056e1
authored
Jul 02, 2024
by
Michael Yang
Committed by
GitHub
Jul 02, 2024
Browse files
Merge pull request #5420 from ollama/mxyng/insecure-path
err on insecure path
parents
d2f19024
88bcd79b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
7 deletions
+25
-7
server/model.go
server/model.go
+3
-5
server/model_test.go
server/model_test.go
+22
-2
No files found.
server/model.go
View file @
400056e1
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"net/http"
"net/http"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/convert"
"github.com/ollama/ollama/convert"
...
@@ -91,12 +90,11 @@ func extractFromZipFile(p string, file *os.File, fn func(api.ProgressResponse))
...
@@ -91,12 +90,11 @@ func extractFromZipFile(p string, file *os.File, fn func(api.ProgressResponse))
fn
(
api
.
ProgressResponse
{
Status
:
"unpacking model metadata"
})
fn
(
api
.
ProgressResponse
{
Status
:
"unpacking model metadata"
})
for
_
,
f
:=
range
r
.
File
{
for
_
,
f
:=
range
r
.
File
{
n
:=
filepath
.
Join
(
p
,
f
.
Name
)
if
!
filepath
.
IsLocal
(
f
.
Name
)
{
if
!
strings
.
HasPrefix
(
n
,
p
)
{
return
fmt
.
Errorf
(
"%w: %s"
,
zip
.
ErrInsecurePath
,
f
.
Name
)
slog
.
Warn
(
"skipped extracting file outside of context"
,
"name"
,
f
.
Name
)
continue
}
}
n
:=
filepath
.
Join
(
p
,
f
.
Name
)
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
n
),
0
o750
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
n
),
0
o750
);
err
!=
nil
{
return
err
return
err
}
}
...
...
server/model_test.go
View file @
400056e1
...
@@ -3,10 +3,12 @@ package server
...
@@ -3,10 +3,12 @@ package server
import
(
import
(
"archive/zip"
"archive/zip"
"bytes"
"bytes"
"errors"
"io"
"io"
"os"
"os"
"path/filepath"
"path/filepath"
"slices"
"slices"
"strings"
"testing"
"testing"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
...
@@ -39,13 +41,31 @@ func TestExtractFromZipFile(t *testing.T) {
...
@@ -39,13 +41,31 @@ func TestExtractFromZipFile(t *testing.T) {
cases
:=
[]
struct
{
cases
:=
[]
struct
{
name
string
name
string
expect
[]
string
expect
[]
string
err
error
}{
}{
{
{
name
:
"good"
,
name
:
"good"
,
expect
:
[]
string
{
"good"
},
expect
:
[]
string
{
"good"
},
},
},
{
{
name
:
filepath
.
Join
(
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
"bad"
),
name
:
strings
.
Join
([]
string
{
"path"
,
".."
,
"to"
,
"good"
},
string
(
os
.
PathSeparator
)),
expect
:
[]
string
{
filepath
.
Join
(
"to"
,
"good"
)},
},
{
name
:
strings
.
Join
([]
string
{
"path"
,
".."
,
"to"
,
".."
,
"good"
},
string
(
os
.
PathSeparator
)),
expect
:
[]
string
{
"good"
},
},
{
name
:
strings
.
Join
([]
string
{
"path"
,
"to"
,
".."
,
".."
,
"good"
},
string
(
os
.
PathSeparator
)),
expect
:
[]
string
{
"good"
},
},
{
name
:
strings
.
Join
([]
string
{
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
".."
,
"bad"
},
string
(
os
.
PathSeparator
)),
err
:
zip
.
ErrInsecurePath
,
},
{
name
:
strings
.
Join
([]
string
{
"path"
,
".."
,
".."
,
"to"
,
"bad"
},
string
(
os
.
PathSeparator
)),
err
:
zip
.
ErrInsecurePath
,
},
},
}
}
...
@@ -55,7 +75,7 @@ func TestExtractFromZipFile(t *testing.T) {
...
@@ -55,7 +75,7 @@ func TestExtractFromZipFile(t *testing.T) {
defer
f
.
Close
()
defer
f
.
Close
()
tempDir
:=
t
.
TempDir
()
tempDir
:=
t
.
TempDir
()
if
err
:=
extractFromZipFile
(
tempDir
,
f
,
func
(
api
.
ProgressResponse
)
{});
err
!=
nil
{
if
err
:=
extractFromZipFile
(
tempDir
,
f
,
func
(
api
.
ProgressResponse
)
{});
!
err
ors
.
Is
(
err
,
tt
.
err
)
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment