Problem/Motivation

Localize.Drupal.org went into an infinite loop due to parsing this PHP code:

$form['description'] = [
      '#type' => 'item',
      '#markup' => $this->t('Add links to be displayed in the footer of emails sent by Symfony Mailer. These links will be available in all languages.<br>Example of usage in the template:<br><pre>@code</pre>', [
        '@code' => <<<TWIG
{% if footer_links is not empty %}
  <tr>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr>
        {% for link in footer_links %}
          <td>{{ link }}</td>
        {% endfor %}
      </tr>
    </table>
  </tr>
{% endif %}
TWIG,
      ]),
    ];

While this looks fine, the problem is at TWIG, which is "flexible heredoc syntax" shipped in PHP 7.3: https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes

Previously the heredoc would only be tokenized as heredoc-end if there was a newline, now the comma can be there. Older PHP does not understand the PHP 7.3+ flexible HEREDOC syntax (indented closing markers and tokens on the same line after the heredoc end). Instead of properly tokenizing them, it treats the entire content including the closing marker AND everything that follows as T_ENCAPSED_AND_WHITESPACE, including all subsequent PHP code!

This was triggered by https://www.drupal.org/project/symfony_mailer_addons/releases/1.0.0-beta1.

Proposed resolution

Add graceful fail for this case and test coverage.

Remaining tasks

User interface changes

API changes

Data model changes

LLM disclosure

LLM was used to analyze the problem, excperiment with solutions and write the tests. Everything was manually reviewed.

Issue fork potx-3563293

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

drumm created an issue. See original summary.

drumm’s picture

Status: Active » Needs review

This looks like the same code change will apply to 8.x-1.x

drumm’s picture

Assigned: drumm » Unassigned

With the patch applied, the logs still have

symfony_mailer_addons-1.0.0-beta1.tar.gz for strings.
Undefined offset: 664 potx.inc:1271                                     [notice]

Which suggests _potx_skip_args() is called with an out-of-bounds $here to begin with. So either the calling code and/or bounds checking at the start of the function could likely be improved.

I don’t have that deep of knowledge of the code here, so someone else should pick this up. The patch deployed so far is sufficient to unblock the production cron.

gábor hojtsy made their first commit to this issue’s fork.

gábor hojtsy’s picture

Title: Infinite loop in _potx_skip_args() » More flexible heredoc/nowdoc syntax parsing is impossible on PHP prior to 7.3, causes infinite loop
Status: Needs review » Reviewed & tested by the community

Accidentally committed the modern port to https://git.drupalcode.org/project/potx/-/commit/c3577a472a8dad2e0b0acaa... directly, that also passed there btw. I will merge the 7.x fix here.

gábor hojtsy’s picture

Issue summary: View changes

Updated issue summary heavily.

gábor hojtsy’s picture

Issue summary: View changes

  • gábor hojtsy committed 3220ebe4 on 7.x-3.x authored by drumm
    fix: #3563293 More flexible heredoc/nowdoc syntax parsing is impossible...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

gábor hojtsy’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.