Skip to:
Content

BuddyPress.org

Opened 6 weeks ago

Last modified 3 weeks ago

#9338 new defect (bug)

14.5.0: sanitize_utf8_filename() can call transliterator_transliterate() when ext-intl is unavailable

Reported by: lverane Owned by:
Priority: normal Milestone: Awaiting Review
Component: Core Version:
Severity: normal Keywords:
Cc: lverane

Description (last modified by lverane)

Reproduction:

PHP 8.2
intl extension disabled
WordPress 7.0.2
BuddyPress 14.5.0
Upload avatar with UTF-8 filename

Cause:

In sanitize_utf8_filename() both instances of function_exists( 'wp_is_valid_utf8' ) ? wp_is_valid_utf8( $retval ) : seems_utf8( $retval ) should be wrapped in parentheses.

File: /wp-content/plugins/buddypress/bp-core/classes/class-bp-attachment.php
Lines 297 - 322

Change History (3)

#1 follow-up: @espellcaste
4 weeks ago

@lverane I don't get it. What's exactly the problem? Is there an error you can share?

In sanitize_utf8_filename() both instances of function_exists( 'wp_is_valid_utf8' ) ? wp_is_valid_utf8( $retval ) : seems_utf8( $retval ) should be wrapped in parentheses.

What does that mean exactly?

#2 in reply to: ↑ 1 @lverane
3 weeks ago

  • Description modified (diff)

Replying to espellcaste:

@lverane I don't get it. What's exactly the problem? Is there an error you can share?

In sanitize_utf8_filename() both instances of function_exists( 'wp_is_valid_utf8' ) ? wp_is_valid_utf8( $retval ) : seems_utf8( $retval ) should be wrapped in parentheses.

What does that mean exactly?

I added the file path to the ticket description. The issue is that the current if statement

if (
  function_exists( 'transliterator_transliterate' )
  // wp_is_valid_utf8 is added in WP 6.9.
  && function_exists( 'wp_is_valid_utf8' ) ? wp_is_valid_utf8( $retval ) : seems_utf8( $retval )
) {

Will resolve as

(function_exists( 'transliterator_transliterate' ) && function_exists( 'wp_is_valid_utf8' )) ? wp_is_valid_utf8( $retval ) : seems_utf8( $retval )

Meaning if function_exists( 'transliterator_transliterate' ) is false and seems_utf8( $retval ) is true transliterator_transliterate() is still called. The fix is to add parentheses around the second evaluation:

function_exists( 'transliterator_transliterate' ) && (function_exists( 'wp_is_valid_utf8' ) ? wp_is_valid_utf8( $retval ) : seems_utf8( $retval ))

Same issue/solution for function_exists( 'iconv' ) on the else statement.

Last edited 3 weeks ago by lverane (previous) (diff)

#3 @lverane
3 weeks ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.