Fix: handle none-utf8 encoding in decompression
This commit is contained in:
parent
16613a6113
commit
14982f5e70
3 changed files with 16 additions and 1 deletions
1
go.mod
1
go.mod
|
@ -33,6 +33,7 @@ require (
|
|||
github.com/upyun/go-sdk v2.1.0+incompatible
|
||||
github.com/zyxar/argo v0.0.0-20190709183644-6096bc0e6414
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
|
||||
golang.org/x/text v0.3.2
|
||||
gopkg.in/go-playground/validator.v8 v8.18.2
|
||||
gopkg.in/ini.v1 v1.51.0 // indirect
|
||||
)
|
||||
|
|
1
go.sum
1
go.sum
|
@ -235,6 +235,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
|
|
|
@ -2,13 +2,17 @@ package filesystem
|
|||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -256,7 +260,16 @@ func (fs *FileSystem) Decompress(ctx context.Context, src, dst string) error {
|
|||
}
|
||||
|
||||
for _, f := range r.File {
|
||||
rawPath := util.FormSlash(f.Name)
|
||||
fileName := f.Name
|
||||
// 处理非UTF-8编码
|
||||
if f.NonUTF8 {
|
||||
i := bytes.NewReader([]byte(fileName))
|
||||
decoder := transform.NewReader(i, simplifiedchinese.GB18030.NewDecoder())
|
||||
content, _ := ioutil.ReadAll(decoder)
|
||||
fileName = string(content)
|
||||
}
|
||||
|
||||
rawPath := util.FormSlash(fileName)
|
||||
savePath := path.Join(dst, rawPath)
|
||||
// 路径是否合法
|
||||
if !strings.HasPrefix(savePath, util.FillSlash(path.Clean(dst))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue