SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
278 stars 42 forks source link

Bug in vars vistor: Tuple object has no attribute value #28

Closed simisimon closed 2 years ago

simisimon commented 2 years ago

I found another problem when I used scalpel for analyzing ML projects. To reproduce the problem, just run the example below.

code_str = """X = dataset.iloc[:, [3, 4]].values"""   

cfg = CFGBuilder().build_from_src(name="", src=code_str)

_, const_dict = SSA().compute_SSA(cfg)

Running this example leads to the following stack trace:

Traceback (most recent call last):
  File "D:\GitHub\test\test_scalpel.py", line 118, in <module>
    main()
  File "D:\GitHub\test\test_scalpel.py", line 92, in main
    _, const_dict = SSA().compute_SSA(cfg)
  File "..\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\SSA\const.py", line 107, in compute_SSA
    stored_idents, loaded_idents, func_names = self.get_stmt_idents_ctx(stmt, const_dict=tmp_const_dict)
  File "C:\Users\ssimon\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\SSA\const.py", line 309, in get_stmt_idents_ctx
    ident_info = get_vars(visit_node)
  File "...\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\core\vars_visitor.py", line 188, in get_vars
    visitor.visit(node)
  File "...\AppData\Local\Programs\Python\Python39\lib\ast.py", line 407, in visit
    return visitor(node)
  File "...\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\core\vars_visitor.py", line 176, in visit_Assign
    self.visit(node.value)
  File "...\AppData\Local\Programs\Python\Python39\lib\ast.py", line 407, in visit
    return visitor(node)
  File "...\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\core\vars_visitor.py", line 113, in visit_Attribute
    self.visit(node.value)
  File "...\AppData\Local\Programs\Python\Python39\lib\ast.py", line 407, in visit
    return visitor(node)
  File "...\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\core\vars_visitor.py", line 151, in visit_Subscript
    self.slicev(node.slice)
  File "...\AppData\Local\Programs\Python\Python39\lib\site-packages\scalpel\core\vars_visitor.py", line 145, in slicev
    self.visit(node.value)
AttributeError: 'Tuple' object has no attribute 'value'

I think it is probably a special case, which is currently not covered by the vars visitor module?

PS: Here is the original file from which I extracted the the code line.

Jarvx commented 2 years ago

Thanks for providing this test case. I will push a bug fix tomorrow!

Jarvx commented 2 years ago

The problem has been fixed. Added some support to Python array slice syntax.