CWEweakness
CWE-194 Unexpected Sign Extension
High
Official page ↗
- Abstraction
- Variant
- Structure
- Simple
- Status
- Incomplete
- Likelihood of exploit
- High
- Languages
- C, C++
- CWE version
- 5.0
Description
The product performs an operation on a number that causes it to be sign extended when it is transformed into a larger data type.
Common consequences
• Integrity, Confidentiality, Availability, Other: Read Memory, Modify Memory, Other — When an unexpected sign extension occurs in code that operates directly on memory buffers, such as a size value or a memory index, then it could cause the program to write or read outside the boundaries of the intended buffer. If the numeric value is associated with an application-level resource, such as a quantity or price for a product in an e-commerce site, then the sign extension could produce a value that is much higher (or lower) than the application's allowable range. When the original number is negative, this can produce unexpected values that lead to resultant weaknesses.
Potential mitigations
• [Implementation] Avoid using signed variables if you don't need to represent negative values. When negative values are needed, perform validation after you save those values to larger data types, or before passing them to functions that are expecting unsigned values.
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.)
Observed examples
• CVE-2018-10887: Chain: unexpected sign extension (CWE-194) leads to integer overflow (CWE-190), causing an out-of-bounds read (CWE-125)
• CVE-1999-0234: Sign extension error produces -1 value that is treated as a command separator, enabling OS command injection.
• CVE-2003-0161: Product uses "char" type for input character. When char is implemented as a signed type, ASCII value 0xFF (255), a sign extension produces a -1 value that is treated as a program-specific separator value, effectively disabling a length check and leading to a buffer overflow. This is also a multiple interpretation error.
• CVE-2007-4988: Chain: signed short width value in image processor is sign extended during conversion to unsigned int, which leads to integer overflow and heap-based buffer overflow.
• CVE-2006-1834: Chain: signedness error allows bypass of a length check; later sign extension makes exploitation easier.
• CVE-2005-2753: Sign extension when manipulating Pascal-style strings leads to integer overflow and improper memory copy.
Related
Observed example · CVE (6)
- CVE-2018-10887 A flaw was found in libgit2 before version 0.27.3. vulnerability
- CVE-2007-4988 Sign extension error in the ReadDIBImage function in ImageMagick before 6.3.5-9 allows context-dependent attackers to execute arbitrary… vulnerability
- CVE-2006-1834 Integer signedness error in Opera before 8.54 allows remote attackers to execute arbitrary code via long values in a stylesheet attribute,… vulnerability
- CVE-2005-2753 Integer overflow in Apple QuickTime before 7.0.3 allows user-assisted attackers to execute arbitrary code via a crafted MOV file that… vulnerability
- CVE-2003-0161 The prescan() function in the address parser (parseaddr.c) in Sendmail before 8.12.9 does not properly handle certain conversions from char… vulnerability
- CVE-1999-0234 Bash treats any character with a value of 255 as a command separator. vulnerability
Child of · CWE (1)
- CWE-681 Incorrect Conversion between Numeric Types weakness
Referenced by CVE · weakness (5)
- CVE-2025-13632 Inappropriate implementation in DevTools in Google Chrome prior to 143.0.7499.41 allowed an attacker who convinced a user to install a… vulnerability
- CVE-2022-32138 In multiple CODESYS products, a remote attacker may craft a request which may cause an unexpected sign extension, resulting in a… vulnerability
- CVE-2021-38434 FATEK Automation WinProladder versions 3.30 and prior lacks proper validation of user-supplied data when parsing project files, which could… vulnerability
- CVE-2020-13544 An exploitable sign extension vulnerability exists in the TextMaker document parsing functionality of SoftMaker Office 2021’s TextMaker… vulnerability
- CVE-2018-10887 A flaw was found in libgit2 before version 0.27.3. vulnerability
Referenced by CWE · can also be (1)
- CWE-197 Numeric Truncation Error weakness