protondrive: skip nodes the server sends without an ID or with a negative size

A node which decrypted was handed on whatever its link ID and encrypted
size, so a faulty or hostile server could make rclone cache a node
under an empty ID or list a file with a negative size. Such nodes are
now left out of listings and logged, as nodes with invalid names are.

Found by FuzzDecodeLink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Opus 5.5 committed 2026-11-11 19:33:39 +01:00
1 parent 32710eefd1
commit 90b2a48e71
2 files changed
+42 -2

No files matched your search

+9 -2
View File
@@ -439,13 +439,17 @@ func annotate(what string, err error) error {
// and parent's key is unverified: whoever made that key could have
// made this one too.
//
// It returns unreadable, and no node, if the node's name or key can't
// be decrypted, its name isn't valid or its type is unknown. err is
// It returns unreadable, and no node, if the node has no ID, its name
// or key can't be decrypted, its name isn't valid, its type is unknown
// or its encrypted size is negative. err is
// set only if the verification keys can't be had. Failed signature
// checks, and extended attributes or hash key which can't be
// decrypted, are logged once per node.
func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parent *nodeKeys) (n *node, unreadable, err error) {
l := &d.Link
if l.LinkID == "" {
return nil, errors.New("node has no ID"), nil
}
parentKR := parent.keyRing
now := c.s.serverTime()
@@ -527,6 +531,9 @@ func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parent *no
case l.Type == api.LinkTypeFile && d.File != nil:
n.MIMEType = d.File.MediaType
if rev := d.File.ActiveRevision; rev != nil {
if rev.EncryptedSize < 0 {
return nil, fmt.Errorf("%q: negative encrypted size %d", truncateName(name), rev.EncryptedSize), nil
}
n.RevisionID = rev.RevisionID
n.EncryptedSize = rev.EncryptedSize
revVerifyKR, err := c.verifyKeys(ctx, rev.SignatureEmail, keys.keyRing)
@@ -1110,3 +1110,36 @@ func TestNewNodesKeepListing(t *testing.T) {
assert.Contains(t, listed, name)
}
}
// TestDecryptNodeRefusesHostileValues checks a node which decrypts but
// which the server describes with values no node can have is
// unreadable, not handed on.
func TestDecryptNodeRefusesHostileValues(t *testing.T) {
t.Parallel()
c, _, u := newTestClient(t)
ctx := context.Background()
fileID := u.SeedFile(u.RootID(), "file.txt", []byte("content"), time.Now())
rootKeys, err := c.folderKeysOf(ctx, c.rootID())
require.NoError(t, err)
for name, change := range map[string]func(d *api.LinkDetails){
"no ID": func(d *api.LinkDetails) { d.Link.LinkID = "" },
"negative encrypted size": func(d *api.LinkDetails) { d.File.ActiveRevision.EncryptedSize = -5 },
} {
t.Run(name, func(t *testing.T) {
links, err := c.fetchLinks(ctx, []string{fileID})
require.NoError(t, err)
require.Len(t, links, 1)
n, unreadable, err := c.decryptNode(ctx, &links[0], rootKeys)
require.NoError(t, err)
require.NoError(t, unreadable, "unchanged")
require.NotNil(t, n)
change(&links[0])
n, unreadable, err = c.decryptNode(ctx, &links[0], rootKeys)
require.NoError(t, err)
assert.Error(t, unreadable)
assert.Nil(t, n)
})
}
}