Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sjuvonen opened this issue Mar 11, 2021 · 1 comment
Open
Labels

Comments

@sjuvonen
Copy link

sjuvonen commented Mar 11, 2021

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)');
    }
}
@martin-georgiev
Copy link
Owner

Thanks for reporting this. Do you mind opening a PR with your proposed solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants