Skip to content

fix(files_external): reject names SMB cannot store before copying - #67680

Open
1358 wants to merge 3 commits into
nextcloud:masterfrom
1358:fix/smb-validate-paths
Open

1358 wants to merge 3 commits into
nextcloud:masterfrom
1358:fix/smb-validate-paths

Conversation

@1358

@1358 1358 commented Dec 4, 2026

Copy link
Copy Markdown

Summary

Follow-up to #67678. Moving or copying a folder to SMB external storage failed half-way when a name inside contains a character SMB does not allow, and the files copied so far stayed in the target. Now:

  • SMB::copyFromStorage() checks all names of the source tree before anything is copied. The move or copy fails with 400 and nothing is created on the share. The message names the path, e.g. event/sub/14:15.mp4: ":" is not allowed inside a file or folder name.
  • SMB::verifyPath() rejects such names up front for uploads (including chunked), new folders and renames, with the existing message for forbidden characters.
  • SMB::getFileInfo() maps icewind's InvalidPathException to not found. I left that out of fix: report invalid SMB names on cross-storage move/copy instead of a 500 #67678 because without the checks above it made a direct upload fail later and without the file name.

The tree check only looks at the characters SMB can't store, not at the filename rules of the instance, so files with names the instance no longer allows can still be moved as before. It lists the source tree once more before copying, which is cheap compared to copying the data.

The characters are the ones icewind/smb enforces. icewind has no getter for them, so they are copied into a constant. The list hasn't changed since 2015, and a test fails if it ever differs from icewind's.

No new strings: the message reuses the one of the filename validator, so this could be backported as well.

How to test

  1. Add an SMB external storage as in fix: report invalid SMB names on cross-storage move/copy instead of a 500 #67678.
  2. Move a folder with a.txt, sub/14:15.mp4 and z.txt onto the SMB mount: HTTP 400, the toast says <folder>/sub/14:15.mp4: ":" is not allowed inside a file or folder name., nothing is created on the share.
  3. On the SMB mount, try to upload 14:15.mp4, create a folder a:b or rename a file to a:b.txt. Each is rejected with HTTP 400 and ":" is not allowed inside a file or folder name.
  4. Moving a folder with valid names still works.

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

1358 added 3 commits December 3, 2026 12:01
When writing a file to the target storage fails, copyFromStorage()
deletes the partially written target. If that unlink() throws as well,
the exception escapes the folder traversal and the move or copy ends in
an HTTP 500. A target name the storage cannot store must still reach
the client, so it can tell which file failed, as it already does when
the top-level target name is invalid.

Signed-off-by: Tom Mittelstädt <1583407+1358@users.noreply.github.com>
icewind/smb throws its own InvalidPathException for names containing
characters SMB does not allow, e.g. ":". fopen() let it escape
unmapped, and unlink() threw for a path that cannot exist on the share.

Signed-off-by: Tom Mittelstädt <1583407+1358@users.noreply.github.com>
Moving or copying a folder to SMB failed half-way when a name inside
contained a character SMB does not allow, and the files copied so far
stayed in the target. Checking the whole tree first lets the operation
fail before anything is copied. Creating, uploading or renaming to such
a name is rejected up front for the same reason.

With these checks in place, looking up such a path can report it as
missing instead of throwing.

Signed-off-by: Tom Mittelstädt <1583407+1358@users.noreply.github.com>
@1358
1358 marked this pull request as ready for review December 4, 2026 07:35
@1358
1358 requested review from a team as code owners December 4, 2026 07:35
@1358
1358 requested review from GhassenKefi, icewind1991, provokateurin and vlotysh and removed request for a team December 4, 2026 07:35

This branch has not been deployed

No deployments
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.

[Bug]: Moving a folder to SMB external storage fails half-way (HTTP 500) if a file inside has a name SMB rejects; partial copy is left behind

1 participant