Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions internal/archive/iso9660/iso9660.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package iso9660

import (
"io"
"os"

"github.com/alist-org/alist/v3/internal/archive/tool"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/stream"
"github.com/kdomanski/iso9660"
"io"
"os"
stdpath "path"
)

type ISO9660 struct {
Expand Down Expand Up @@ -78,7 +78,10 @@ func (ISO9660) Decompress(ss []*stream.SeekableStream, outputPath string, args m
}
if obj.IsDir() {
if args.InnerPath != "/" {
outputPath = stdpath.Join(outputPath, obj.Name())
outputPath, err = tool.SecureJoin(outputPath, obj.Name())
if err != nil {
return err
}
if err = os.MkdirAll(outputPath, 0700); err != nil {
return err
}
Expand Down
26 changes: 21 additions & 5 deletions internal/archive/iso9660/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package iso9660

import (
"io"
"os"
stdpath "path"
"path/filepath"
"strings"

"github.com/alist-org/alist/v3/internal/archive/tool"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/stream"
Expand Down Expand Up @@ -62,15 +64,26 @@ func toModelObj(file *iso9660.File) model.Obj {
}

func decompress(f *iso9660.File, path string, up model.UpdateProgress) error {
file, err := os.OpenFile(stdpath.Join(path, f.Name()), os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
return decompressEntry(f.Reader(), f.Size(), path, f.Name(), up)
}

func decompressEntry(reader io.Reader, size int64, path, entryName string, up model.UpdateProgress) error {
dstPath, err := tool.SecureJoin(path, entryName)
if err != nil {
return err
}
if err = os.MkdirAll(filepath.Dir(dstPath), 0700); err != nil {
return err
}
file, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
if err != nil {
return err
}
defer file.Close()
_, err = utils.CopyWithBuffer(file, &stream.ReaderUpdatingProgress{
Reader: &stream.SimpleReaderWithSize{
Reader: f.Reader(),
Size: f.Size(),
Reader: reader,
Size: size,
},
UpdateProgress: up,
})
Expand All @@ -84,7 +97,10 @@ func decompressAll(children []*iso9660.File, path string) error {
if err != nil {
return err
}
nextPath := stdpath.Join(path, child.Name())
nextPath, err := tool.SecureJoin(path, child.Name())
if err != nil {
return err
}
if err = os.MkdirAll(nextPath, 0700); err != nil {
return err
}
Expand Down
Loading