Executive brief
Gravity is a programming language compiler that parses source code into executable instructions. A parsing bug allows an attacker to trigger an out-of-bounds memory read by crafting malicious code with a trailing '0' character, potentially causing the application to crash or leak sensitive memory contents.
Technical details
The vulnerability is an out-of-bounds read (CWE-125) in the parse_number_expression function within src/compiler/gravity_parser.c. The parser checks whether a numeric literal uses a prefix (0x, 0b, 0o) by testing if value[0]=='0' and then unconditionally accessing value[1] via toupper(value[1]), without bounds checking. When a source file ends with a single '0' character (e.g., "= 0"), value[1] points one byte past the allocated buffer, causing a deterministic 1-byte heap out-of-bounds read. An attacker can trigger this by providing malicious Gravity source code with a trailing '0' to a compiler or interpreter instance. This results in information disclosure (memory leak) and potential crash under memory sanitizers. Version 0.9.8 and patch commit 1b9bbf3ad5749e2a3434e6ad073c6e93c24207b6 fix this issue.
Affected products
- marcobambini Gravity up to 0.9.7
Timeline
- 2026-09-14: disclosed
- 2026-09-14: patched: Version 0.9.8 and patch commit 1b9bbf3ad5749e2a3434e6ad073c6e93c24207b6