Fix TypeDesc.__str__ crash on certain DIEs - #664
Conversation
|
@pmhahn PTAL - this is likely related to the typing changes |
eliben
left a comment
There was a problem hiding this comment.
The PR fails the type checker
However, simply initializing the name to the empty string should do the trick?
|
I would have to look closer... I can imagine that change would make the type checker pass but I think it would also change the behavior of |
There was a problem hiding this comment.
My cd4da4b is the relevant change, which no longer initializes self.name = None
Can you please provide a (minimal) sample of the ELF file, so we can add it to the test suite? It's probably enough if you can publish the C-code, which generates such a problematic DIE, so we can add the C code as a minimal example, compile it ourself and add the resulting ELF file to the repository.
|
|
||
| class ClassDesc: | ||
| def __init__(self) -> None: | ||
| self.scopes: tuple[str, ...] = () |
There was a problem hiding this comment.
This is required because of line 204, where the name: str | None are collected:
| self.scopes: tuple[str | None, ...] = () |
When my team attempted to upgrade from pyelftools==0.32 to pyelftools==0.33, we found that some of our binary inspection tools were broken by the upgrade. In particular,
elftools.dwarf.datatype_cpp.describe_cpp_datatypecrashes when fed certain inputs, such as:Here is the specific error we encountered:
This appears likely to be related to this change:
v0.32...v0.33#diff-266d689a3956c69d57de4c617fb8e426c32469e6e7f4f0459df93d7fc6b5ae65L133-R151
Since TypeDesc.name is no longer being initialized to None, there are code paths where it does not get initialized before
__str__is called, which results in the AttributeError shown above. I propose to resume initializing the variable to None, which fixes the crash for us.