{5.4] [AI] [com_media] Allow image editor to re-save file back to original non-ASCII filename#47935
Conversation
…ames LocalAdapter::checkContent() is shared by createFile() and updateFile(). On update the filename is already on disk; canUpload()'s name-equality guard against File::makeSafe() rejects every existing non-ASCII name and the editor returns 403 instead of saving. Pass the makeSafe'd name into canUpload() so the size, MIME and executable-extension checks still run. New uploads with non-ASCII names are still blocked up-front by getSafeName(). Fixes joomla#47934
|
What would happen if your filesystem has both files |
|
@brianteeman That is not the issue being fixed, and having an The premise being that someone decided to upload |
Reformat the multi-line explanatory comment to /* */ C-style with a leading * on each line, matching the space/tab rules used by doc blocks, per review feedback on comment blocks longer than two lines. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
My question was because my reading of the change says that it uses a temporary "safe" filename and I am wondering what happens if a file exists already that has the same name as the temporary filename |
|
@brianteeman Aah, yes, that is a relevant point. I guess that it depends if |
Summary
The Joomla 5 media manager's built-in image editor returns HTTP 403 with
JLIB_MEDIA_ERROR_UPLOAD_INPUTwhenever the user tries to save an edit to a file whose existing name on disk contains non-ASCII characters (e.g.erik_schön.jpg,λογότυπο.png, files placed by FTP / migration / sample data).Fixes #47934.
Reproduction
The PUT to
index.php?option=com_media&task=api.files&path=local-images:/…/erik_schön.jpgreturns:{ "success": false, "message": "The file could not be uploaded.", "messages": { "error": ["The file name must only contain alphanumeric characters and no spaces."] } }Root cause
LocalAdapter::checkContent()(plugins/filesystem/local/src/Adapter/LocalAdapter.php) is called from bothcreateFile()andupdateFile()and runs the incoming filename throughMediaHelper::canUpload():canUpload()(libraries/src/Helper/MediaHelper.php) enforces:File::makeSafe()transliterates non-ASCII characters viaAny-Latin; Latin-ASCII+iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", …), soerik_schön.jpg !== erik_schon.jpg, the guard fires, andcheckContentthrows 403.The check is correct for uploads — new files with non-ASCII names are deliberately not accepted by the media manager. It is incorrect for in-place updates, where the filename is fixed on disk and the operation only rewrites the bytes. The size, MIME and executable-extension checks performed by the same
canUpload()call are still wanted and should keep running.Fix
Pass
File::makeSafe(\$name)intocanUpload()so the name-equality test trivially passes while the content checks still run. New uploads continue to be blocked up-front bygetSafeName()increateFile()/createFolder(), so this only changes behaviour for in-place edits of pre-existing files.Test plan
erik_schön.jpg) in com_media's image editor, rotate it, save → file is rewritten on disk, no 403.getSafeName()as before..php.jpg) on top of an existing non-ASCII file → still rejected bycanUpload()'s extension check.Documentation Changes Required
None.
Generative AI disclosure
Per the Joomla Generative AI Policy: this patch was drafted with Claude (Anthropic) assistance during root-cause analysis of the 403 above. The fix is one line + comment; the reporter (me) reproduced the bug on a real Joomla 5.4 site, applied the patch, and verified all four scenarios above pass before opening this PR.