Skip to content

fix(rclone): guard nil Item in GetFilesSize to avoid panic#328

Merged
lovehunter9 merged 1 commit into
mainfrom
for_cli
May 22, 2026
Merged

fix(rclone): guard nil Item in GetFilesSize to avoid panic#328
lovehunter9 merged 1 commit into
mainfrom
for_cli

Conversation

@lovehunter9
Copy link
Copy Markdown
Collaborator

Summary

Guard against resp.Item == nil in the file branch of
(*rclone).GetFilesSize, so a missing remote no longer crashes
the request handler.

Background

When precheck runs against a cloud source whose path lacks a
trailing slash, FileParam.IsFile() reports isFile=true and
GetFilesSize takes the Stat(..., FilesOnly: true) branch.
If the underlying remote actually resolves to a directory (or
does not exist at all), rclone's operations/stat endpoint
responds with:

{ "item": null }

The previous code dereferenced resp.Item.Size unconditionally
and panicked with runtime error: invalid memory address or nil pointer dereference. Hertz's recovery middleware kept the
process alive but the response was already partially written, so
the client saw an HTTP 200 with a corrupted body — symptom on
the wire was a body of just 1 instead of a normal JSON envelope.

Fix

Treat resp == nil || resp.Item == nil as "file not found" and
return a descriptive error. precheck.checkCloud already wraps
any GetFilesSize error into the standard Source path to copy does not exist or is not accessible. 500 response, so this
aligns the cloud failure surface with the existing sync-source
behaviour.

The same nil-guard pattern is already used in
pkg/drivers/clouds/service.go (the file-stat path), so this is
consistent with prior art in the codebase.

Test plan

  • Cloud paste (S3 / Tencent COS / Drive) with source missing
    the trailing slash on a path that resolves to a directory
    → expect HTTP 500 + "Source path to copy does not exist or
    is not accessible.", no panic in server logs.
  • Cloud paste with a valid file source (with or without
    trailing slash) still succeeds end-to-end.
  • Cloud paste with a valid directory source (trailing
    slash present) still succeeds end-to-end.

Made with Cursor

When the remote does not resolve to a regular file, rclone's Stat
endpoint returns {"item": null}. The file branch of GetFilesSize
dereferenced resp.Item directly and panicked, which surfaced as a
500 with a corrupted body during precheck for cloud sources whose
trailing slash was lost. Treat nil Item as "file not found" so
checkCloud can wrap it into the standard source-not-found error.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lovehunter9 lovehunter9 merged commit 4edaaf5 into main May 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant