Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#49979 new defect (bug)

file_get_contents(): read of 8192 bytes failed with errno=21 Is a directory in /wp-includes/l10n.php on line 1096

Reported by: lwangaman's profile Lwangaman Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.4
Component: I18N Keywords: has-patch reporter-feedback
Focuses: Cc:

Description

Using PHP 7.4.5 I have started getting this error when editing pages in the admin area. Seems like "." and ".." are now being read along with the files in a directory perhaps.

For now I have patched my l10n.php with a further check if $file is a directory:

<?php
        /**
         * Filters the file path for loading script translations for the given script handle and text domain.
         *
         * @since 5.0.2
         *
         * @param string|false $file   Path to the translation file to load. False if there isn't one.
         * @param string       $handle Name of the script to register a translation domain to.
         * @param string       $domain The text domain.
         */
        $file = apply_filters( 'load_script_translation_file', $file, $handle, $domain );

        if ( ! $file || ! is_readable( $file ) || is_dir($file) ) {
                return false;
        }

        $translations = file_get_contents( $file );

Change History (4)

#1 @SergeyBiryukov
4 years ago

  • Keywords reporter-feedback removed

This ticket was mentioned in PR #257 on WordPress/wordpress-develop by kraftbj.


4 years ago
#2

Defensive coding to avoid an error when trying to file_get_contents of a directory.

I think this is an incomplete solution, though, as _why_ is a directory being passed. This would at least prevent the PHP warning.

Trac ticket: https://core.trac.wordpress.org/ticket/49979

#3 @kraftbj
4 years ago

  • Keywords has-patch added; needs-patch removed

#4 @ocean90
4 years ago

  • Keywords reporter-feedback added

Hello @Lwangaman, welcome to WordPress Trac!

Thanks for the report. Are you able to check what the value of $file is when a warning is thrown? Does it happen with specific plugins active? Adding a random is_dir() check should be avoided as it doesn't fix the root cause and this is probably also an issue for plugins using the filters in load_script_translations().

Note: See TracTickets for help on using tickets.