Make WordPress Core

Opened 6 months ago

Closed 5 months ago

Last modified 4 months ago

#61794 closed defect (bug) (fixed)

Bugfix in class-wp-translation-file-mo for "PHP Warning: Undefined array key 1 in"

Reported by: pander's profile pander Owned by: swissspidy's profile swissspidy
Milestone: 6.7 Priority: low
Severity: minor Version: 6.5
Component: I18N Keywords: has-patch commit
Focuses: Cc:

Description

The warning "PHP Warning: Undefined array key 1 in" is flooding the error log file of my web service running WordPress.

I think the plugin that is the cause of this warning for me is https://github.com/qtranslate/qtranslate-xt/ or https://icalevents.com/ but I have seen it being reported for many different plugins.

Line 161 of wp-includes/l10n/class-wp-translation-file-mo.php is triggering this, is

<?php
list( $name, $value ) = array_map( 'trim', explode( ':', $meta_line, 2 ) );

To prevent the warning, I have changed line 157 from

<?php
if ( '' === $meta_line ) {

to

<?php
if ( '' === $meta_line || strpos($meta_line, ':') === false ) {

I know the warning is valid and should be fixed elsewhere, but my knowledge of WordPress is limited and this fix prevents that performance is impeded. Perhaps the warning should be caught in a different way, but this fixed it for now for me.

If there are way to pinpoint better what is causing this, please let me know. I can help to locate it but need some guidance.

Change History (11)

#1 @swissspidy
6 months ago

  • Component changed from General to I18N
  • Focuses performance removed
  • Owner set to swissspidy
  • Status changed from new to assigned

Removing performance focus as this is not related to performance.

#2 @swissspidy
6 months ago

The fix sounds reasonable to me, it adds some hardening.

If there are way to pinpoint better what is causing this, please let me know. I can help to locate it but need some guidance.

One of your plugins has an invalid MO file. You can try a `var_dump( $this->file ) on line 160 to find the culprit.

#3 @swissspidy
6 months ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 6.7
  • Priority changed from normal to low
  • Version changed from 6.6.1 to 6.5

@mukesh27 commented on PR #7116:


6 months ago
#6

@swissspidy Already opened #7115

#7 @swissspidy
5 months ago

  • Keywords commit added

#8 @swissspidy
5 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58922:

I18N: Add hardening for invalid meta lines in MO files.

Props swissspidy, pander.
Fixes #61794.

#10 @pander
5 months ago

Thanks. The culprit is

string(97) "/var/www/DOMAINNAME/wp-content/plugins/amr-ical-events-list/lang/amr-ical-events-list-nl_NL.mo"

and that was repeated 1142 times.

I regenerated the MO file with

cd /var/www/DOMAINNAME/wp-content/plugins/amr-ical-events-list/lang
mv amr-ical-events-list-nl_NL.mo /tmp
msgfmt amr-ical-events-list-nl_NL.po -o amr-ical-events-list-nl_NL.mo

and this fixed it.

#11 @swissspidy
4 months ago

#62097 was marked as a duplicate.

Note: See TracTickets for help on using tickets.