Skip to content

Media: Guard gutenberg_delete_heic_companion_file() against non-string $metadata['original']#78128

Merged
ramonjd merged 2 commits into
trunkfrom
fix/heic-companion-non-string-original
May 12, 2026
Merged

Media: Guard gutenberg_delete_heic_companion_file() against non-string $metadata['original']#78128
ramonjd merged 2 commits into
trunkfrom
fix/heic-companion-non-string-original

Conversation

@lancewillett
Copy link
Copy Markdown
Contributor

What?

Closes #78127.

Adds an is_string() guard to gutenberg_delete_heic_companion_file() so it bails on attachments whose wp_get_attachment_metadata()['original'] is not a string filename.

Why?

The function is hooked to delete_attachment for all attachment types and assumes $metadata['original'] is a string (the HEIC sideload's companion filename). Other attachment types — or any plugin filtering wp_get_attachment_metadata — may legitimately put a non-string value (commonly an array) at the original key.

The existing empty() check passes for a non-empty array, so the bad value reaches path_join() -> path_is_absolute() -> wp_is_stream() -> strpos(), which throws:

Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given

Full repro and stack trace in #78127.

How?

Extends the early bail to require is_string( $metadata['original'] ). One-line change.

Testing Instructions

  1. Apply this PR.
  2. Add the filter from gutenberg_delete_heic_companion_file() fatals when $metadata['original'] is not a string #78127:
    add_filter( 'wp_get_attachment_metadata', function ( $data ) {
        return array_merge( (array) $data, [ 'original' => [ 'foo' => 'bar' ] ] );
    } );
  3. Delete an attachment: wp_delete_attachment( $id, true );
  • Before: TypeError from strpos() inside gutenberg_delete_heic_companion_file().
  • After: silent no-op for non-string original; HEIC cleanup unaffected when original is 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.

@lancewillett lancewillett requested a review from spacedmonkey as a code owner May 9, 2026 20:27
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: lancewillett <lancewillett@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Flaky tests detected in d7df117.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25687914524
📝 Reported issues:

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Client Side Media Media processing in the browser with WASM labels May 11, 2026
Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ramonjd
Copy link
Copy Markdown
Member

ramonjd commented May 12, 2026

LGTM I'll merge this and provide an update on WordPress/wordpress-develop#11323

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Client Side Media Media processing in the browser with WASM [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gutenberg_delete_heic_companion_file() fatals when $metadata['original'] is not a string

4 participants