Skip to content

Conversation

@fkil
Copy link

@fkil fkil commented Nov 25, 2025

Fixes #8696

The checks for extreme values when transforming <= to < were incomplete and relied on undefined behavior, making compilers optimize them out.

Specifically, for SLESS_EQUAL, the decompiler relied on integer overflows. For integers smaller than 8 bytes, no overflow will occur when adding 1, resulting in a missed case and, thus, x <= INT_MAX will become x < INT_MIN. For the signed case when subtracting one, the compiler removes the check due to undefined behavior, resulting in another missed case.

To fix this, add helper functions for computing maximum and minimum values for signed and unsigned varnodes and directly check for them.

Fixes NationalSecurityAgency#8696

The checks for extreme values when transforming <= to < were incomplete
and relied on undefined behavior, making compilers optimize them out.

Specifically, for SLESS_EQUAL, the decompiler relied on integer overflows.
For integers smaller than 8 bytes, no overflow will occur when adding 1,
resulting in a missed case and, thus, x <= INT_MAX will become x < INT_MIN.
For the signed case when subtracting one, the compiler removes the check
due to undefined behavior, resulting in another missed case.

To fix this, add helper functions for computing maximum and minimum values
for signed and unsigned varnodes and directly check for them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: Decompiler Status: Triage Information is being gathered

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decompiler: Ghidra erroneously converts x <= SIGNED_INT_N_MAX to x < SIGNED_INT_N_MIN

3 participants