CWEweakness
CWE-196 Unsigned to Signed Conversion Error
Medium
Official page ↗
- Abstraction
- Variant
- Structure
- Simple
- Status
- Draft
- Likelihood of exploit
- Medium
- Languages
- C, C++
- CWE version
- 5.0
Description
The product uses an unsigned primitive and performs a cast to a signed primitive, which can produce an unexpected value if the value of the unsigned primitive can not be represented using a signed primitive.
Common consequences
• Availability: DoS: Crash, Exit, or Restart — Incorrect sign conversions generally lead to undefined behavior, and therefore crashes.
• Integrity: Modify Memory — If a poor cast leads to a buffer overflow or similar condition, data integrity may be affected. This can be a precursor to dangerous buffer underwrite conditions that allow attackers to move down the stack where they otherwise might not have access in a normal buffer overflow condition. Buffer underwrites occur frequently when large unsigned values are cast to signed values, and then used as indexes into a buffer or for pointer arithmetic.
• Integrity, Confidentiality, Availability, Access Control: Execute Unauthorized Code or Commands, Bypass Protection Mechanism — Improper signed-to-unsigned conversions without proper checking can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program's implicit security policy.
Potential mitigations
• [Requirements] Choose a language which is not subject to these casting flaws.
• [Architecture and Design] Design object accessor functions to implicitly check values for valid sizes. Ensure that all functions which will be used as a size are checked previous to use as a size. If the language permits, throw exceptions rather than using in-band errors.
• [Implementation] Error check the return values of all functions. Be aware of implicit casts made, and use unsigned variables for sizes if at all possible.
Detection methods
• Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
Related
Attack pattern · CAPEC (1)
- CAPEC-92 Forced Integer Overflow attack pattern
Can precede · CWE (1)
- CWE-124 Buffer Underwrite weakness
Child of · CWE (1)
- CWE-681 Incorrect Conversion between Numeric Types weakness
Referenced by CAPEC · weakness (1)
- CAPEC-92 Forced Integer Overflow attack pattern
Referenced by CVE · weakness (9)
- CVE-2026-106567 ImageMagick is free and open-source software used for editing and manipulating digital images. vulnerability
- CVE-2026-93019 Imager versions before 1.036 for Perl exit the process reading a TGA with a colour map length of 32768 or more in tga_palette_read. vulnerability
- CVE-2026-58317 Unsigned to Signed Conversion Error (CWE-196) vulnerability exists in TTSSH2 plugin of Tera Term provided by TeraTerm Project. vulnerability
- CVE-2026-14454 Imager versions before 1.033 for Perl treat unsigned EXIF IFD entry counts as signed. vulnerability
- CVE-2026-34155 RAUC controls the update process on embedded Linux systems. vulnerability
- CVE-2023-0185 NVIDIA GPU Display Driver for Linux contains a vulnerability in the kernel mode layer, where sign conversion issuescasting an unsigned… vulnerability
- CVE-2022-36025 Besu is a Java-based Ethereum client. vulnerability
- CVE-2020-13545 An exploitable signed conversion vulnerability exists in the TextMaker document parsing functionality of SoftMaker Office 2021’s TextMaker… vulnerability
- CVE-2020-7067 In PHP versions 7.2.x below 7.2.30, 7.3.x below 7.3.17 and 7.4.x below 7.4.5, if PHP is compiled with EBCDIC support (uncommon),… vulnerability
Referenced by CWE · can also be (1)
- CWE-197 Numeric Truncation Error weakness