11package iso9660
22
33import (
4+ "io"
45 "os"
5- stdpath "path"
6+ "path/filepath "
67 "strings"
78
9+ "github.com/alist-org/alist/v3/internal/archive/tool"
810 "github.com/alist-org/alist/v3/internal/errs"
911 "github.com/alist-org/alist/v3/internal/model"
1012 "github.com/alist-org/alist/v3/internal/stream"
@@ -62,15 +64,26 @@ func toModelObj(file *iso9660.File) model.Obj {
6264}
6365
6466func decompress (f * iso9660.File , path string , up model.UpdateProgress ) error {
65- file , err := os .OpenFile (stdpath .Join (path , f .Name ()), os .O_WRONLY | os .O_CREATE | os .O_EXCL , 0600 )
67+ return decompressEntry (f .Reader (), f .Size (), path , f .Name (), up )
68+ }
69+
70+ func decompressEntry (reader io.Reader , size int64 , path , entryName string , up model.UpdateProgress ) error {
71+ dstPath , err := tool .SecureJoin (path , entryName )
72+ if err != nil {
73+ return err
74+ }
75+ if err = os .MkdirAll (filepath .Dir (dstPath ), 0700 ); err != nil {
76+ return err
77+ }
78+ file , err := os .OpenFile (dstPath , os .O_WRONLY | os .O_CREATE | os .O_EXCL , 0600 )
6679 if err != nil {
6780 return err
6881 }
6982 defer file .Close ()
7083 _ , err = utils .CopyWithBuffer (file , & stream.ReaderUpdatingProgress {
7184 Reader : & stream.SimpleReaderWithSize {
72- Reader : f . Reader () ,
73- Size : f . Size () ,
85+ Reader : reader ,
86+ Size : size ,
7487 },
7588 UpdateProgress : up ,
7689 })
@@ -84,7 +97,10 @@ func decompressAll(children []*iso9660.File, path string) error {
8497 if err != nil {
8598 return err
8699 }
87- nextPath := stdpath .Join (path , child .Name ())
100+ nextPath , err := tool .SecureJoin (path , child .Name ())
101+ if err != nil {
102+ return err
103+ }
88104 if err = os .MkdirAll (nextPath , 0700 ); err != nil {
89105 return err
90106 }
0 commit comments