https://en.wikipedia.org/wiki/Mac_OS_Roman
"bytes"
"encoding/binary"
"errors"
"bytes"
"encoding/binary"
"errors"
"io"
"path/filepath"
"strings"
"io"
"path/filepath"
"strings"
subPath,
filepath.Join("/", string(fileName)),
)
subPath,
filepath.Join("/", string(fileName)),
)
+ fullPath, err = txtDecoder.String(fullPath)
+ if err != nil {
+ return "", fmt.Errorf("invalid filepath encoding: %w", err)
+ }
}
strippedName := strings.ReplaceAll(file.Name(), ".incomplete", "")
}
strippedName := strings.ReplaceAll(file.Name(), ".incomplete", "")
+ strippedName, err = txtEncoder.String(strippedName)
+ if err != nil {
+ return nil, err
+ }
nameSize := make([]byte, 2)
binary.BigEndian.PutUint16(nameSize, uint16(len(strippedName)))
nameSize := make([]byte, 2)
binary.BigEndian.PutUint16(nameSize, uint16(len(strippedName)))
"fmt"
"github.com/go-playground/validator/v10"
"go.uber.org/zap"
"fmt"
"github.com/go-playground/validator/v10"
"go.uber.org/zap"
+ "golang.org/x/text/encoding/charmap"
"gopkg.in/yaml.v3"
"io"
"io/fs"
"gopkg.in/yaml.v3"
"io"
"io/fs"
+// Converts bytes from Mac Roman encoding to UTF-8
+var txtDecoder = charmap.Macintosh.NewDecoder()
+
+// Converts bytes from UTF-8 to Mac Roman encoding
+var txtEncoder = charmap.Macintosh.NewEncoder()
+
type Server struct {
NetInterface string
Port int
type Server struct {
NetInterface string
Port int
+ encodedName, err := txtEncoder.String(fw.name)
+ if err != nil {
+ return res, fmt.Errorf("invalid filepath encoding: %w", err)
+ }
+
res = append(res, cc.NewReply(t,
res = append(res, cc.NewReply(t,
- NewField(FieldFileName, []byte(fw.name)),
+ NewField(FieldFileName, []byte(encodedName)),
NewField(FieldFileTypeString, fw.ffo.FlatFileInformationFork.friendlyType()),
NewField(FieldFileCreatorString, fw.ffo.FlatFileInformationFork.friendlyCreator()),
NewField(FieldFileComment, fw.ffo.FlatFileInformationFork.Comment),
NewField(FieldFileTypeString, fw.ffo.FlatFileInformationFork.friendlyType()),
NewField(FieldFileCreatorString, fw.ffo.FlatFileInformationFork.friendlyCreator()),
NewField(FieldFileComment, fw.ffo.FlatFileInformationFork.Comment),
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
- hlFile.name = string(fileNewName)
+ hlFile.name, err = txtDecoder.String(string(fileNewName))
+ if err != nil {
+ return res, fmt.Errorf("invalid filepath encoding: %w", err)
+ }
+
err = hlFile.move(fileDir)
if os.IsNotExist(err) {
res = append(res, cc.NewErrReply(t, "Cannot rename file "+string(fileName)+" because it does not exist or cannot be found."))
err = hlFile.move(fileDir)
if os.IsNotExist(err) {
res = append(res, cc.NewErrReply(t, "Cannot rename file "+string(fileName)+" because it does not exist or cannot be found."))
res = append(res, cc.NewErrReply(t, "Cannot delete file "+fileName+" because it does not exist or cannot be found."))
return res, err
}
res = append(res, cc.NewErrReply(t, "Cannot delete file "+fileName+" because it does not exist or cannot be found."))
return res, err
}
- if err != nil {
- return res, err
- }
switch mode := fi.Mode(); {
case mode.IsDir():
if !cc.Authorize(accessMoveFolder) {
switch mode := fi.Mode(); {
case mode.IsDir():
if !cc.Authorize(accessMoveFolder) {
}
}
newFolderPath := path.Join(cc.Server.Config.FileRoot, subPath, folderName)
}
}
newFolderPath := path.Join(cc.Server.Config.FileRoot, subPath, folderName)
+ newFolderPath, err = txtDecoder.String(newFolderPath)
+ if err != nil {
+ return res, fmt.Errorf("invalid filepath encoding: %w", err)
+ }
// TODO: check path and folder name lengths
// TODO: check path and folder name lengths
return []Transaction{cc.NewErrReply(t, msg)}, nil
}
return []Transaction{cc.NewErrReply(t, msg)}, nil
}
- // TODO: check for disallowed characters to maintain compatibility for original client
-
if err := cc.Server.FS.Mkdir(newFolderPath, 0777); err != nil {
msg := fmt.Sprintf("Cannot create folder \"%s\" because an error occurred.", folderName)
return []Transaction{cc.NewErrReply(t, msg)}, nil
if err := cc.Server.FS.Mkdir(newFolderPath, 0777); err != nil {
msg := fmt.Sprintf("Cannot create folder \"%s\" because an error occurred.", folderName)
return []Transaction{cc.NewErrReply(t, msg)}, nil