Skip to content

Commit

Permalink
Fix node key decoding error "illegal base64 data at input byte 22"
Browse files Browse the repository at this point in the history
Apparently some node keys have / in and need to be split at that point.

https://github.com/meganz/sdk/blob/66d9c1b5c5b43699fbd5881ba9de8a2eb43c97eb/src/node.cpp#L906

Thanks to Ajaja for figuring this out.

See: https://forum.rclone.org/t/problem-to-login-with-mega/12276
  • Loading branch information
ncw committed Jan 11, 2020
1 parent e8695d7 commit ad0abe7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions mega.go
Expand Up @@ -704,11 +704,20 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
switch {
case itm.T == FOLDER || itm.T == FILE:
args := strings.Split(itm.Key, ":")
if len(args) < 2 {
return nil, fmt.Errorf("not enough : in item.Key: %q", itm.Key)
}
itemUser, itemKey := args[0], args[1]
itemKeyParts := strings.Split(itemKey, "/")
if len(itemKeyParts) >= 2 {
itemKey = itemKeyParts[0]
// the other part is maybe a share key handle?
}

switch {
// File or folder owned by current user
case args[0] == itm.User:
buf, err := base64urldecode(args[1])
case itemUser == itm.User:
buf, err := base64urldecode(itemKey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -736,7 +745,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
}

m.FS.skmap[itm.Hash] = itm.SKey
buf, err := base64urldecode(args[1])
buf, err := base64urldecode(itemKey)
if err != nil {
return nil, err
}
Expand All @@ -750,7 +759,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
}
// Shared file
default:
k := m.FS.skmap[args[0]]
k := m.FS.skmap[itemUser]
b, err := base64urldecode(k)
if err != nil {
return nil, err
Expand All @@ -763,7 +772,7 @@ func (m *Mega) addFSNode(itm FSNode) (*Node, error) {
if err != nil {
return nil, err
}
buf, err := base64urldecode(args[1])
buf, err := base64urldecode(itemKey)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ad0abe7

Please sign in to comment.