WerWolv / ImHex

🔍 A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.
https://imhex.werwolv.net
GNU General Public License v2.0
44.62k stars 1.95k forks source link

[Bug] Crashes on Evaluate when Pattern Data is sorted by Value #1938

Open c6-dev opened 3 days ago

c6-dev commented 3 days ago

Operating System

Windows

What's the issue you encountered?

ImHex crashes when hitting "Evaluate" with about 30% chance, it seems to happen with various files and patterns at random on both stable and nightly versions, i have attached an example binary, pattern and a crash log. Crash logs always seem to point at hex::ui::PatternDrawer::sortPatterns. Please let me know if there is any additional context i can provide - this started out of nowhere and causes a lot of frustration.

How can the issue be reproduced?

Load the attached file, paste the pattern code, hit "Evaluate" 5-10 times - it crashes.

ImHex Version

1.36.0

ImHex Build Type

Installation type

MSI

Additional context?

BINARY.zip pattern.txt crash_log_20241019_100658.log

Update: only seems to happen when Pattern Data window is sorted by Value.

c6-dev commented 3 days ago

Oh, just as I posted the issue I noticed something - the Pattern Data window was sorted by Value tab. If I sort it by Name, the crashes don't seem to happen. As soon as i click on Value tab header and Evaluate a few times it dies.

paxcut commented 3 days ago

the bug is not related to evaluation but rather at the sorting process itself. I was able to reproduce it by simply clicking on the value headers which triggers the sort. As noted above the error is in sortPatterns and it happens in this line:

     result = left->getValue() <=> right->getValue();

the reason the segfault is triggered is the value of the right pattern pointer as shown in the following image: image

I couldn't track back to why the right pointer is so wrong. both pointers are arguments to a lambda function but thats all I could find.