• CWE-197: Numeric Truncation Error

Truncation errors arise when a primitive data type is cast to a primitive of a smaller size, resulting in data loss during the conversion. This loss of information can lead to inaccuracies and unexpected behavior within the application.

CWE-197: Numeric Truncation Error

CWE ID: 197
Name: Numeric Truncation Error

Beschreibung

Truncation errors arise when a primitive data type is cast to a primitive of a smaller size, resulting in data loss during the conversion. This loss of information can lead to inaccuracies and unexpected behavior within the application.

Erweiterte Beschreibung

When a primitive data type is cast to a smaller primitive, the high-order bits of the larger value are lost during the conversion, potentially resulting in an unexpected value that is not equal to the original. This value may be required as an index into a buffer, a loop iterator, or simply necessary state data. In any case, the value cannot be trusted and the system will be in an undefined state. While this method may be employed viably to isolate the low bits of a value, this usage is rare, and truncation usually implies that an implementation error has occurred.

Risikominderungsmaßnahmen

Maßnahme (Implementation)

Effektivität: Unknown
Beschreibung: Stellen Sie sicher, dass keine Casts, implizit oder explizit, stattfinden, die von einem größeren zu einem kleineren primitiven Datentyp oder umgekehrt erfolgen.