Skip to content

Integer Truncation Error

Description

Truncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion. The value cannot be trusted and the application will be in an undefined state.

Examples

Insecure Code

c
char narrow = (char) 1024;

Secure Code

c
int narrow = 1024;

Remediation

Ensure that the destination variable is large enough to hold the value being assigned to it. Consider using a larger data type or validating the value before assignment.

Rule Details

FieldValue
IDCODE-0669
CategoryGeneric
SeverityMEDIUM
CWECWE-197
ConfidenceMEDIUM
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsinteger-truncation, data-loss
OWASPN/A

References