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

[Bug] [pysrc2cpg] Class inheritance does not recognize generic parent classes #4831

Open
wunused opened this issue Aug 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@wunused
Copy link
Contributor

wunused commented Aug 8, 2024

Describe the bug

For Python class TypeDecl nodes that inherit from generic classes, Joern does not recognize the inherited class when it is specialized. This is the case for both the inheritedTypeFullName and baseType fields.

To Reproduce

  1. Create analysis test:

generic.py

import typing

T = typing.TypeVar("T")

class GenericFoo(typing.Generic[T]):
    pass

class SomeMixin(object):
    pass

class IntFoo(GenericFoo[int], SomeMixin):
    pass
  1. Analyze with Joern
$ ./joern-parse generic.py -o generic.cpg
$ ./joern generic.cpg
joern> cpg.typeDecl("IntFoo").inheritsFromTypeFullName.l
val res1: List[String] = List(
  ":<module>.py:<module>.SomeMixin",
  "<body>/:<module>.py:<module>.SomeMixin",
  "<metaClassCallHandler>/:<module>.py:<module>.SomeMixin",
  "<fakeNew>/:<module>.py:<module>.SomeMixin"
)
joern> cpg.typeDecl("IntFoo").baseType.l
val res2: List[io.shiftleft.codepropertygraph.generated.nodes.Type] = List(
  Type(
    id = 86L,
    fullName = ":<module>.SomeMixin",
    name = "SomeMixin",
    typeDeclFullName = ":<module>.SomeMixin"
  )
)

For this example, GenericFoo is not recognized as an inherited class of IntFoo. In other examples, I have observed e.g., "GenericFoo[int]" listed in the inheritedTypeFullName field, but without recognizing that "GenericFoo[int]" is the same class as "GenericFoo".

Expected behavior

The inheritedTypeFullName and baseType fields list "GenericFoo" as an inherited class of IntFoo.

Desktop (please complete the following information):

  • OS: Debian 12
  • Joern Version: 2.0.385
  • Java version: 19.0.2

Additional context

I know I am on an outdated version of Joern, but on the most up-to-date build I cannot get a CPG to load when analyzing Python projects. I do not see any recent commit messages related to this, but I apologize if this is a recently fixed issue.

@wunused wunused added the bug Something isn't working label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant