Description
The product uses a signed primitive and performs a cast to an unsigned primitive, which can produce an unexpected value if the value of the signed primitive can not be represented using an unsigned primitive.
It is dangerous to rely on implicit casts between signed and unsigned numbers because the result can take on an unexpected value and violate assumptions made by the program. Often, functions will return negative values to indicate a failure. When the result of a function is to be used as a size parameter, using these negative return values can have unexpected results. For example, if negative size values are passed to the standard memory copy or allocation functions they will be implicitly cast to a large unsigned value. This may lead to an exploitable buffer overflow or underflow condition.
Potential Impact
Integrity
Unexpected State
Demonstrative Examples
unsigned int readdata () {int amount = 0;...if (result == ERROR)amount = -1;...return amount;}unsigned int readdata () {int amount = 0;...amount = accessmainframe();...return amount;}DataPacket *packet;int numHeaders;PacketHeader *headers;
sock=AcceptSocketConnection();ReadPacket(packet, sock);numHeaders =packet->headers;
if (numHeaders > 100) {ExitError("too many headers!");}headers = malloc(numHeaders * sizeof(PacketHeader);ParsePacketHeaders(packet, headers);char* processNext(char* strm) {char buf[512];short len = *(short*) strm;strm += sizeof(len);if (len <= 512) {memcpy(buf, strm, len);process(buf);return strm + len;}else {return -1;}}Detection Methods
- Automated Static Analysis High — 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 sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2025-27363 | Font rendering library does not properly handle assigning a signed short value to an unsigned long (CWE-195), leading to an integer wraparound (CWE-190), c |
| CVE-2007-4268 | Chain: integer signedness error (CWE-195) passes signed comparison, leading to heap overflow (CWE-122) |
Related Weaknesses
Taxonomy Mappings
- CLASP: — Signed to unsigned conversion error
- Software Fault Patterns: SFP1 — Glitch in computation
- CERT C Secure Coding: INT31-C — Ensure that integer conversions do not result in lost or misinterpreted data
Frequently Asked Questions
What is CWE-195?
CWE-195 (Signed to Unsigned Conversion Error) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The product uses a signed primitive and performs a cast to an unsigned primitive, which can produce an unexpected value if the value of the signed primitive can not be represented using an unsigned pr...
How can CWE-195 be exploited?
Attackers can exploit CWE-195 (Signed to Unsigned Conversion Error) to unexpected state. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-195?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-195?
CWE-195 is classified as a Variant-level weakness (Low-Medium abstraction). It has been observed in 2 real-world CVEs.