Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CWE-197 (数值截断错误) — Vulnerability Class 39

39 vulnerabilities classified as CWE-197 (数值截断错误). AI Chinese analysis included.

CWE-197, Numeric Truncation Error, is a software weakness occurring when a value is cast from a larger primitive type to a smaller one, causing high-order bits to be discarded and resulting in data loss. This flaw is typically exploited by attackers who manipulate input values to trigger unexpected numeric conversions, potentially leading to buffer overflows, out-of-bounds memory access, or logic errors when the truncated value serves as an array index or loop iterator. Developers can prevent this vulnerability by implementing rigorous input validation to ensure values fit within the target data type’s range before casting. Additionally, using safe conversion functions, enabling compiler warnings for implicit narrowing conversions, and employing static analysis tools to detect potential truncation scenarios during the development lifecycle are essential strategies for mitigating this risk and maintaining application integrity.

MITRE CWE Description
Truncation errors occur when a primitive is cast to a primitive of a smaller size and data is lost in the conversion. When a primitive is cast to a smaller primitive, the high order bits of the large value are lost in the conversion, potentially resulting in an unexpected value that is not equal to the original value. 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.
Common Consequences (1)
IntegrityModify Memory
The true value of the data is lost and corrupted data is used.
Mitigations (1)
ImplementationEnsure that no casts, implicit or explicit, take place that move from a larger size primitive or a smaller size primitive.
Examples (2)
This example, while not exploitable, shows the possible mangling of values associated with truncation errors:
int intPrimitive; short shortPrimitive; intPrimitive = (int)(~((int)0) ^ (1 << (sizeof(int)*8-1))); shortPrimitive = intPrimitive; printf("Int MAXINT: %d\nShort MAXINT: %d\n", intPrimitive, shortPrimitive);
Bad · C
Int MAXINT: 2147483647 Short MAXINT: -1
Result
In the following Java example, the method updateSalesForProduct is part of a business application class that updates the sales information for a particular product. The method receives as arguments the product ID and the integer amount sold. The product ID is used to retrieve the total product count from an inventory object which returns the count as an integer. Before calling the method of the sa…
... // update sales database for number of product sold with product ID public void updateSalesForProduct(String productID, int amountSold) { // get the total number of products in inventory database int productCount = inventory.getProductCount(productID); // convert integer values to short, the method for the // sales object requires the parameters to be of type short short count = (short) productCount; short sold = (short) amountSold; // update sales database for product sales.updateSalesCount(productID, count, sold); } ...
Bad · Java
... // update sales database for number of product sold with product ID public void updateSalesForProduct(String productID, int amountSold) { // get the total number of products in inventory database int productCount = inventory.getProductCount(productID); // make sure that integer numbers are not greater than // maximum value for type short before converting if ((productCount < Short.MAX_VALUE) && (amountSold < Short.MAX_VALUE)) { // convert integer values to short, the method for the // sales object requires the parameters to be of type short short count = (short) productCount; short sold = 
Good · Java
CVE IDTitleCVSSSeverityPublished
CVE-2024-21310 Windows Cloud Files Mini Filter Driver Elevation of Privilege Vulnerability — Windows 10 Version 1809 7.8 High2024-01-09
CVE-2023-36641 Fortinet FortiProxy 安全漏洞 — FortiProxy 6.2 Medium2023-11-14
CVE-2023-36710 Windows Media Foundation Core Remote Code Execution Vulnerability — Windows 10 Version 1809 7.8 High2023-10-10
CVE-2023-35328 Windows Transaction Manager Elevation of Privilege Vulnerability — Windows 10 Version 1809 7.8 High2023-07-11
CVE-2022-42475 Fortinet FortiOS 缓冲区错误漏洞 — FortiProxy 9.3 Critical2023-01-02
CVE-2022-34680 NVIDIA GPU Display Driver 安全漏洞 — vGPU software (guest driver) - Linux, vGPU software (Virtual GPU Manager), NVIDIA Cloud Gaming (guest driver), NVIDIA Cloud Gaming (Virtual GPU Manager) 5.5 Medium2022-12-30
CVE-2022-34676 NVIDIA GPU Display Driver 缓冲区错误漏洞 — vGPU software (guest driver) - Linux, vGPU software (Virtual GPU Manager), NVIDIA Cloud Gaming (guest driver), NVIDIA Cloud Gaming (Virtual GPU Manager) 7.1 High2022-12-30
CVE-2022-34670 NVIDIA GPU Display Driver 安全漏洞 — vGPU software (guest driver) - Linux, vGPU software (Virtual GPU Manager), NVIDIA Cloud Gaming (guest driver), NVIDIA Cloud Gaming (Virtual GPU Manager) 7.8 High2022-12-30
CVE-2020-15202 Integer truncation in Shard API usage — tensorflow 9.0 Critical2020-09-25

Vulnerabilities classified as CWE-197 (数值截断错误) represent 39 CVEs. The CWE taxonomy describes the weakness; review individual CVEs for product-specific impact.