|
@@ -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) {
|
|
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) {
|
|
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) {}); !errors.Is(err, tt.err) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
|