Wrap-around Error

Incomplete Base
Structure: Simple
Description

A wrap-around error happens when a variable exceeds the maximum value its data type can hold, causing it to unexpectedly reset to a very small, negative, or undefined number instead of increasing further.

Extended Description

This flaw, often called integer overflow or wraparound, is common in operations like counters, loops, or memory allocation where a value is repeatedly incremented. Developers might assume a number will simply stop increasing, but in languages like C or C++, it silently cycles back to the minimum, leading to crashes, incorrect calculations, or security vulnerabilities like buffer overflows. Detecting these errors manually is tricky because they depend on specific data types and runtime values. While SAST tools can flag risky code patterns, Plexicus uses AI to not only identify the risk but also suggest the precise code fix—such as using larger data types or boundary checks—automating remediation and saving hours of manual review across your application portfolio.

Common Consequences 3
Scope: Availability

Impact: DoS: Crash, Exit, or RestartDoS: Resource Consumption (CPU)DoS: Resource Consumption (Memory)DoS: Instability

This weakness will generally lead to undefined behavior and therefore crashes. In the case of overflows involving loop index variables, the likelihood of infinite loops is also high.

Scope: Integrity

Impact: Modify Memory

If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the wrap around results in other conditions such as buffer overflows, further memory corruption may occur.

Scope: ConfidentialityAvailabilityAccess Control

Impact: Execute Unauthorized Code or CommandsBypass Protection Mechanism

This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program's implicit security policy.

Potential Mitigations 3
Requirements specification: The choice could be made to use a language that is not susceptible to these issues.
Phase: Architecture and Design
Provide clear upper and lower bounds on the scale of any protocols designed.
Phase: Implementation
Perform validation on all incremented variables to ensure that they remain within reasonable bounds.
Demonstrative Examples 1

ID : DX-33

The following image processing code allocates a table for images.

Code Example:

Bad
C
c
This code intends to allocate a table of size num_imgs, however as num_imgs grows large, the calculation determining the size of the list will eventually overflow (Integer Overflow or Wraparound). This will result in a very small list to be allocated instead. If the subsequent code operates on the list as if it were num_imgs long, it may result in many types of out-of-bounds problems (Improper Restriction of Operations within the Bounds of a Memory Buffer).
References 3
24 Deadly Sins of Software Security
Michael Howard, David LeBlanc, and John Viega
McGraw-Hill
2010
ID: REF-44
The Art of Software Security Assessment
Mark Dowd, John McDonald, and Justin Schuh
Addison Wesley
2006
ID: REF-62
The CLASP Application Security Process
Secure Software, Inc.
2005
ID: REF-18
Likelihood of Exploit

Medium

Applicable Platforms
Languages:
C : OftenC++ : Often
Modes of Introduction
Implementation
Taxonomy Mapping
  • CLASP
  • CERT C Secure Coding
  • Software Fault Patterns
Notes
RelationshipThe relationship between overflow and wrap-around needs to be examined more closely, since several entries (including Integer Overflow or Wraparound) are closely related.