NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
49.12k stars 5.65k forks source link

[floats] missing sign of minus zero in listings view, truncated precision in decompiler view #6677

Open intrigus-lgtm opened 6 days ago

intrigus-lgtm commented 6 days ago

Describe the bug

  1. Ghidra does not properly show the sign of minus zero (0.0f) (it's 0x8000_0000): Listing view (incorrect): grafik Decompiler view (correct): grafik

  2. Ghidra truncates floats incorrectly in the decompiler view only: Listing view (correct): grafik Decompiler view (incorrect): grafik

To Reproduce Steps to reproduce the behavior:

  1. Compile this code:

float minus_zero; float plus_zero; float positive_infinity; float negative_infinity; float precision_problem;

int main(int argc, char **argv) {

minus_zero = -0.0f;
plus_zero = 0.0f;
positive_infinity = 1 / 0.0f;
negative_infinity = -1 / 0.0f;
precision_problem = 2.4912346E12f;
return 0;

}


2. `gcc float.c -o float` or similar
4. Import the binary into ghidra.
5. Give the float type to the constants.
6. Observe that minus zero is missing its minus sign in the listings view (only) and that the precision of `2.4912346E12f` is wrong in the decompiler view (only).

**Expected behavior**
1. Minus sign is not missing in the listings view
2. `2.4912346E12f` is shown correctly in the decompiler view.

**Attachments**
[float.tar.gz](https://github.com/user-attachments/files/16016168/float.tar.gz)

**Environment (please complete the following information):**
Ghidra Version: 11.1.1
Ghidra Release: PUBLIC
Ghidra Build Date: 2024-Jun-14 1025 EDT
Ghidra Revision: febbeb447af1f059d583b11d7cefc8758b99f887
Ghidra Development Mode: false
OS Name: Linux
OS Arch: amd64
OS Version: 6.1.0-21-amd64
OS Pretty Name: Debian GNU/Linux 12 (bookworm)
Java Vendor: Eclipse Adoptium
Java Version: 22.0.1

**Additional context**
Originally found in the context of Google CTF's ieee challenge.