WerWolv / ImHex

🔍 A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.

Home Page:https://imhex.werwolv.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Crash when parsing pattern with undefined struct inside conditional

bgilbert opened this issue · comments

Operating System

Linux

What's the issue you encountered?

Parsing this pattern crashes ImHex:

struct Foo {
    u8 v;
    if (v == 0) {
        Missing m;
    }
};

Foo foo @ 0;

How can the issue be reproduced?

See above

ImHex Version

v1.33.0-184-gef99e9d6f8db

ImHex Build Type

  • Nightly or built from sources

Installation type

Source

Additional context?

This correctly throws a parse error:

struct Foo {
    u8 v;
    Missing m;
};

Foo foo @ 0;

Most likely due to the creation of nullptr nodes that were assumed to be impossible to create but was recently found not to be the case. when there is missing or incorrect notation inside loops or conditionals, these AST node pointers are created which point to zero.Then the nodes attempt to clone themselves using ptr->clone() which raises an invalid address exception crashing Imhex. The reason why these nodes are created and how to avoid them has to do with smart pointers and how they handle special cases.