Digitill
Digitill

Reputation: 41

Illegal length modifier specified

I started getting this error in my Drupal 8 site when I try to load a few different admin pages after clearing the site cache.

Fatal error: Illegal length modifier specified 'f' in s[np]printf call in /public_html/mysite.com/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php on line 88

The offending line of code is the last line in the following snippet.

// Move the temporary file into the proper directory. Note that POSIX
// compliant systems as well as modern Windows perform the rename operation
// atomically, i.e. there is no point at which another process attempting to
// access the new path will find it missing.
$directory = $this->getContainingDirectoryFullPath($name);
$this->ensureDirectory($directory);
$full_path = $this->getFullPath($name, $directory, $mtime);
$result = rename($temporary_path, $full_path);

I logged the variables being used in the php rename function

$temporary_path = sites/default/files/php/twig/.Lmc1W8Ah3a0Ti25OSi6EWRhRrak
$full_path = sites/default/files/php/twig/5eb6d88f951ea_input.html.twig_BDyoxtSNo6EAtdqLkk7vWqrEZ/Y3dUT4hvb70S6IlToElkUoP3liser_VNlYRsxFliuEg.php

The rename() function in the MTimeProtectedFastFileStorage.php file is part of Drupal's caching system. When the site cache is cleared Drupal rebuilds these php twig cache files on page loads as needed.

The rename() function successfully creates the $full_path twig file in the proper directory before the page load crashes with the spprintf "Fatal error: Illegal length modifier specified 'f'" php_error message. The php_error message code is generated on line 741

https://github.com/php/php-src/blob/master/main/spprintf.c

fmt_error:
php_error(E_ERROR, "Illegal length modifier specified '%c' in s[np]printf call", *fmt);
/*
* The default case is for unrecognized %'s.
* We print %<char> to help the user identify what
* option is not understood.

I'm not sure where the php spprintf string formatting function would be called during the rename() file change process. After some testing I do not believe the issue has anything to do with file character length, illegal characters, or file permissions.

Every time you refresh the page a new twig file is successfully created right before the spprintf php_error is thrown. After a number of page refreshes the php_error problem will stop and the remainder of the twig cache files will be created without any further issues.

I'm not sure how to test internal php errors and I'm not sure what "Illegal length modifier specified 'f'" is referring to in the spprintf.c file. Any insight into this matter would be appreciated.

Upvotes: 2

Views: 1570

Answers (1)

Digitill
Digitill

Reputation: 41

I'm not sure what the problem is, but switching to PHP 7.4 makes the issue go away. I'm running PHP 7.4.8 and I am not experiencing this issue any more.

Upvotes: 2

Related Questions