Media: Guard gutenberg_delete_heic_companion_file() against non-string $metadata['original']#78128
Conversation
…g $metadata['original']
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Flaky tests detected in d7df117. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25687914524
|
mikachan
left a comment
There was a problem hiding this comment.
This change looks good to me, thank you!
I've also updated the related backport changelog file to allow the checks to pass on this PR.
|
LGTM I'll merge this and provide an update on WordPress/wordpress-develop#11323 |
What?
Closes #78127.
Adds an
is_string()guard togutenberg_delete_heic_companion_file()so it bails on attachments whosewp_get_attachment_metadata()['original']is not a string filename.Why?
The function is hooked to
delete_attachmentfor all attachment types and assumes$metadata['original']is a string (the HEIC sideload's companion filename). Other attachment types — or any plugin filteringwp_get_attachment_metadata— may legitimately put a non-string value (commonly an array) at theoriginalkey.The existing
empty()check passes for a non-empty array, so the bad value reachespath_join()->path_is_absolute()->wp_is_stream()->strpos(), which throws:Full repro and stack trace in #78127.
How?
Extends the early bail to require
is_string( $metadata['original'] ). One-line change.Testing Instructions
wp_delete_attachment( $id, true );strpos()insidegutenberg_delete_heic_companion_file().original; HEIC cleanup unaffected whenoriginalis a string filename.Testing Instructions for Keyboard
N/A — server-side fix, no UI.
Screenshots or screencast
N/A — server-side fix, no UI.
Use of AI Tools
AI-assisted analysis identified the type-safety gap and drafted the one-line guard. The author reviewed the diff, repro, and PR body before submitting.