[wp-trac] [WordPress Trac] #64849: Media: wp_get_image_alttext() incorrectly treats strpos() position 0 as "not found"
WordPress Trac
noreply at wordpress.org
Sat Mar 14 05:44:42 UTC 2026
#64849: Media: wp_get_image_alttext() incorrectly treats strpos() position 0 as
"not found"
-------------------------------------+------------------------
Reporter: suhan2411 | Owner: joedolson
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: 7.0
Component: Media | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch needs-testing | Focuses:
-------------------------------------+------------------------
Comment (by alexodiy):
Tested PR [https://github.com/WordPress/wordpress-develop/pull/11237
#11237] on PHP 8.5.1 (NTS, Windows x64) against trunk at r61991.
== Environment ==
* PHP: 8.5.1 (cli) NTS Visual C++ 2022 x64
* WordPress: 7.0-beta5 (trunk r61991)
* OS: Windows 11
== Reproduction ==
Created a synthetic binary file where `<x:xmpmeta` starts at byte position
0, containing valid IPTC `AltTextAccessibility` metadata with value "Test
alt text from XMP".
'''Before patch:'''
`strpos()` returns `int(0)` for `$xmp_start`. The check `if ( ! $xmp_start
)` evaluates `! 0` as `true`, causing the function to return an empty
string. Valid XMP metadata is silently ignored.
'''After patch:'''
The check `if ( false === $xmp_start )` correctly distinguishes `0` from
`false`. The function extracts and returns the alt text "Test alt text
from XMP".
== Additional test: file_get_contents failure ==
When `file_get_contents()` returns `false` (e.g., non-existent file path),
the added guard `if ( false === $img_contents )` prevents passing `false`
to `strpos()`.
== Results ==
||= Scenario =||= Before Patch =||= After Patch =||
|| XMP at position 0 || Alt text lost (false negative) || Alt text
correctly extracted ||
|| XMP at position > 0 || Works || Works ||
|| Non-existent file || Passes `false` to `strpos()` || Returns empty
string safely ||
Patch looks correct and minimal. +1 for commit.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64849#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list