Skip to content

dissect.cstruct size field shadowing #1175

Open
@qkaiser

Description

@qkaiser

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CI/CDPull request that updates our Github CI/CDenhancementNew feature or requestpythonPull requests that update Python code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions