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

Infinite loop on parameter that shadows a name in its own type #923

Closed
andersk opened this issue Jun 5, 2020 · 2 comments · Fixed by semgrep/pfff#153
Closed

Infinite loop on parameter that shadows a name in its own type #923

andersk opened this issue Jun 5, 2020 · 2 comments · Fixed by semgrep/pfff#153
Assignees
Labels
bug Something isn't working performance priority:high Issue requires immediate attention

Comments

@andersk
Copy link

andersk commented Jun 5, 2020

This case, reduced from zulip/zerver/lib/email_mirror.py, causes semgrep to spin in an infinite loop:

https://semgrep.live/GdeG

Pattern:

if $X:
    $S
else:
    $S

Code:

import email.message as message

def process_message(message: message.Message):
    if 1:
        message
    else:
        message
@ievans
Copy link
Member

ievans commented Jun 5, 2020

Oof. Thanks for the bug report @andersk!

@ievans ievans added bug Something isn't working performance priority:high Issue requires immediate attention labels Jun 5, 2020
andersk added a commit to andersk/zulip that referenced this issue Jun 5, 2020
They confuse semgrep, and also, like, people in general.

semgrep/semgrep#923

Signed-off-by: Anders Kaseorg <anders@zulip.com>
timabbott pushed a commit to zulip/zulip that referenced this issue Jun 5, 2020
They confuse semgrep, and also, like, people in general.

semgrep/semgrep#923

Signed-off-by: Anders Kaseorg <anders@zulip.com>
clarammdantas pushed a commit to clarammdantas/zulip that referenced this issue Jun 5, 2020
They confuse semgrep, and also, like, people in general.

semgrep/semgrep#923

Signed-off-by: Anders Kaseorg <anders@zulip.com>
Jagansivam28 pushed a commit to Jagansivam28/zulip that referenced this issue Jun 8, 2020
They confuse semgrep, and also, like, people in general.

semgrep/semgrep#923

Signed-off-by: Anders Kaseorg <anders@zulip.com>
@aryx aryx self-assigned this Jun 9, 2020
@aryx
Copy link
Collaborator

aryx commented Jun 9, 2020

It's a bug in the Naming_AST.ml phase.
Looking.

aryx added a commit to semgrep/pfff that referenced this issue Jun 9, 2020
This should fix semgrep/semgrep#923

The issue was that we now annotate certain expression Id with their type,
but in some languages such as Python where there is no clean types,
they use expressions to represent type and those type can then contain
Id that will get associate a type and create cycle in the generic AST,
which then lead certain code (e.g., dumper) to loop forever.

test plan:
regression tests included
make test
~/pfff/pfff -naming_generic shadow_...py does not loop forever anymore
aryx added a commit to semgrep/pfff that referenced this issue Jun 9, 2020
This is related to semgrep/semgrep#923

In my previous fix I've disabled the recursion on OtherType to avoid
creating cycles in the AST but doing so I've introduced some regressions
in semgrep (in tests/python/misc_regression1.py) because we were not
resolving correctly aliases anymore.

This fixes the fix.

Test plan:
+ /home/pad/pfff/pfff -dump_ast -naming_generic python/misc_regression1.py
now shows the right id_resolved

and we still do not go into infinite loop
aryx added a commit that referenced this issue Jun 10, 2020
Show that issue #923 is also fixed with latest pfff
aryx added a commit that referenced this issue Jun 10, 2020
* Use new FieldDef

This shows that issue #941 should now be fixed

test plan:
test file included

* * semgrep-core/tests/python/misc_naming_bug.py:

Show that issue #923 is also fixed with latest pfff

* * pfff: use latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working performance priority:high Issue requires immediate attention
Development

Successfully merging a pull request may close this issue.

3 participants