CWE-197: Numeric Truncation Error
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.
Consequences
- Integrity: Modify Memory
How to prevent it
- Implementation: Ensure that no casts, implicit or explicit, take place that move from a larger size primitive or a smaller size primitive.
Recent advisories
- GHSA-897f-g5gm-fmxm — Wasmtime: Bit-packing in Cranelift compiler causes silent overflow and miscompilation
- CVE-2022-42475 — A heap-based buffer overflow vulnerability [CWE-122] in FortiOS SSL-VPN 7.2.0 through 7.2.2, 7.0.0 through 7.0.8, 6.4.0 through 6.4.10, 6.2.0 through 6.2.11,…
- GHSA-h6fg-mjxg-hqq4 — Integer truncation in Shard API usage
MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.
Check your repos with MergeHarbor