Skip to content

Arithmetic expression inside greatest() leads to infinite parsing loop #87

@sjuvonen

Description

@sjuvonen

I noticed that using an arithmetic operation inside greatest() causes parser to enter an infinite loop.

My doctrine/dbal is at version 2.12.1.

Consider this working example:

$result = $this->doctrine
    ->getManagerForClass(Foo::class)
    ->createQueryBuilder()

      // Here e.g. "sqrt(30) * 100" triggers infinite loop but plain "sqrt(30)" will work just fine.
      ->select('
          greatest(
              sqrt(30) * 100,
              sqrt(11) * 150
          )
          AS score
      ')
      ->from(Foo::class, 'a')
      ->getQuery()
      ->getResult()
      ;

var_dump($result);

My understanding of the parser is limited but I managed to make this behavior stop by overriding $commonNodeMapping in Greatest.php. I have no idea what this will break in exchange...

class Greatest extends BaseVariadicFunction
{
    // Default seems to be 'StringPrimary'.
    protected $commonNodeMapping = 'SimpleArithmeticExpression';

    protected function customiseFunction(): void
    {
        $this->setFunctionPrototype('greatest(%s)');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions