You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Uploaded files are saved with garbled non-ASCII names and overwrite existing files with the same name #458
Uploading a file with an existing name silently overwrites the old one.handleFileUpload calls fs.promises.writeFile(path.join(uploadDir, safeName), data), which replaces whatever is already there. This is easy to hit from a phone: iOS Safari names every camera photo image.jpg, so sending two photos leaves only the second one in ReinShared, with no warning.
Send a photo from the iOS camera roll (image.jpg), then send a different one → only one image.jpg exists, containing the second photo.
I also reproduced both against handleFileUpload directly with a local HTTP server and Node's FormData (which encodes file names the same way browsers do):
Decode the part header bytes as UTF-8 (body.subarray(headerStart, headerEnd).toString("utf8")). The latin1 string is still fine for finding offsets, since its indices match byte positions.
Write with the wx flag and fall back to name (1).ext, name (2).ext, … on EEXIST, which also avoids two simultaneous uploads racing for the same name.
Add a test file for the upload handler covering both cases.
Thanks @Aryan-en! I'm working on the fix now and should have a PR up soon. Testing on macOS and iOS Safari would really help, since non-ASCII names in multipart uploads are where Safari tends to behave differently. I'll tag you on the PR once it's open.
Just to clarify, I had already started working on this and opened PR #459 with the UTF-8 filename fix, collision-safe file saving, and regression tests.
I realize we're working on overlapping implementations, and I definitely don't want to duplicate efforts.
I'm happy to coordinate on the fix and help test it on macOS and iOS Safari. We can compare approaches and incorporate whichever implementation works best.
Activity
Aryan-en commentedon Nov 4, 2026
Hi @mayank609, thanks for the detailed reproduction and proposed fix!
I was looking into this issue as well. I noticed you've mentioned wanting to work on it, so I don't want to duplicate your efforts.
If you'd find it useful, I'd be happy to help with regression tests, review the implementation, or test the fix across macOS and iOS Safari.
Let me know what would be most helpful!
fix(file-share): preserve UTF-8 filenames and prevent upload overwrites
mayank609 commentedon Nov 4, 2026
Thanks @Aryan-en! I'm working on the fix now and should have a PR up soon. Testing on macOS and iOS Safari would really help, since non-ASCII names in multipart uploads are where Safari tends to behave differently. I'll tag you on the PR once it's open.
Aryan-en commentedon Nov 4, 2026
Thanks @mayank609!
Just to clarify, I had already started working on this and opened PR #459 with the UTF-8 filename fix, collision-safe file saving, and regression tests.
I realize we're working on overlapping implementations, and I definitely don't want to duplicate efforts.
I'm happy to coordinate on the fix and help test it on macOS and iOS Safari. We can compare approaches and incorporate whichever implementation works best.
Let me know what you think!
gitcordapp commentedon Nov 4, 2026
Link your account with Gitcord
Thanks for opening this issue, @mayank609!
To receive Discord notifications and contributor tracking for this organization:
/link mayank609/verify-link mayank609)Once linked, Gitcord can notify you about assignments, mentions, and more.
— Posted by Gitcord