Open
Description
I'd like to add a semgrep scan in pre-commit and CI to make sure that we're not using fields named size
in our C definitions consumed by StructParser
.
It's not causing problems right now, but I recently discovered that having a size
field in the struct shadows the size
attribute of the generated object, which is set to the size of that object. It can become a problem when using that size
attribute in complex parsing situations. Just want to remove that footgun.
Here's an example:
>>> cstruct().load("typedef struct something { uint32 magic; uint32 size; }").something(b"AAAABBBB").size
1111638594
>>> cstruct().load("typedef struct something { uint32 magic; uint32 my_size; }").something(b"AAAABBBB").size
8