CWEweakness

CWE-129 Improper Validation of Array Index

High Official page ↗
Alternate terms
out-of-bounds array index, index-out-of-range, array index underflow
Abstraction
Variant
Structure
Simple
Status
Draft
Likelihood of exploit
High
Languages
C, C++, Not Language-Specific
CWE version
5.0

Description

The product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index to ensure the index references a valid position within the array.

Common consequences

• Integrity, Availability: DoS: Crash, Exit, or Restart — Use of an index that is outside the bounds of an array will very likely result in the corruption of relevant memory and perhaps instructions, leading to a crash, if the values are outside of the valid memory area. • Integrity: Modify Memory — If the memory corrupted is data, rather than instructions, the system will continue to function with improper values. • Confidentiality, Integrity: Modify Memory, Read Memory — Use of an index that is outside the bounds of an array can also trigger out-of-bounds read or write operations, or operations on the wrong objects; i.e., "buffer overflows" are not always the result. This may result in the exposure or modification of sensitive data. • Integrity, Confidentiality, Availability: Execute Unauthorized Code or Commands — If the memory accessible by the attacker can be effectively controlled, it may be possible to execute arbitrary code, as with a standard buffer overflow and possibly without the use of large inputs if a precise index can be controlled. • Integrity, Availability, Confidentiality: DoS: Crash, Exit, or Restart, Execute Unauthorized Code or Commands, Read Memory, Modify Memory — A single fault could allow either an overflow (CWE-788) or underflow (CWE-786) of the array index. What happens next will depend on the type of operation being performed out of bounds, but can expose sensitive information, cause a system crash, or possibly lead to arbitrary code execution.

Potential mitigations

• [Architecture and Design] Use an input validation framework such as Struts or the OWASP ESAPI Validation API. Note that using a framework does not automatically address all input validation problems; be mindful of weaknesses that could arise from misusing the framework itself (CWE-1173). • [Architecture and Design] For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server. Even though client-side checks provide minimal benefits with respect to server-side security, they are still useful. First, they can support intrusion detection. If the server receives input that should have been rejected by the client, then it may be an indication of an attack. Second, client-side error-checking can provide helpful feedback to the user about the expectations for valid input. Third, there may be a reduction in server-side processing time for accidental input errors, although this is typically a small savings. • [Requirements] Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, Ada allows the programmer to constrain the values of a variable and languages such as Java and Ruby will allow the programmer to handle exceptions when an out-of-bounds index is accessed. • [Operation, Build and Compilation] Run or compile the software using features or extensions that randomly arrange the positions of a program's executable and libraries in memory. Because this makes the addresses unpredictable, it can prevent an attacker from reliably jumping to exploitable code. Examples include Address Space Layout Randomization (ASLR) [REF-58] [REF-60] and Position-Independent Executables (PIE) [REF-64]. Imported modules may be similarly realigned if their default memory addresses conflict with other modules, in a process known as "rebasing" (for Windows) and "prelinking" (for Linux) [REF-1332] using randomly generated addresses. ASLR for libraries cannot be used in conjunction with prelink since it would require relocating the libraries at run-time, defeating the whole purpose of prelinking. For more information on these techniques see D3-SAOR (Segment Address Offset Randomization) from D3FEND [REF-1335]. • [Operation] Use a CPU and operating system that offers Data Execution Protection (using hardware NX or XD bits) or the equivalent techniques that simulate this feature in software, such as PaX [REF-60] [REF-61]. These techniques ensure that any instruction executed is exclusively at a memory address that is part of the code segment. For more information on these techniques see D3-PSEP (Process Segment Execution Prevention) from D3FEND [REF-1336]. • [Implementation] Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. When accessing a user-controlled array index, use a stringent range of values that are within the target array. Make sure that you do not allow negative values to be used. That is, verify the minimum as well as the maximum of the range of acceptable values. • [Implementation] Be especially careful to validate all input when invoking code that crosses language boundaries, such as from an interpreted language to native code. This could create an unexpected interaction between the language boundaries. Ensure that you are not violating any of the expectations of the language with which you are interfacing. For example, even though Java may not be susceptible to buffer overflows, providing a large argument in a call to native code might trigger an overflow. • [Architecture and Design, Operation] Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations. • [Architecture and Design, Operation] Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software. OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.

Detection methods

• Automated Static Analysis: This weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives. Automated static analysis generally does not account for environmental considerations when reporting out-of-bounds memory operations. This can make it difficult for users to determine which warnings should be investigated first. For example, an analysis tool might report array index errors that originate from command line arguments in a program that is not expected to run with setuid or other special privileges. • Automated Dynamic Analysis: This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results. • Automated Dynamic Analysis: Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ [REF-1518]. • Black Box: Black box methods might not get the needed code coverage within limited time constraints, and a dynamic test might not produce any noticeable side effects even if it is successful.

Observed examples

• CVE-2005-0369: large ID in packet used as array index • CVE-2001-1009: negative array index as argument to POP LIST command • CVE-2003-0721: Integer signedness error leads to negative array index • CVE-2004-1189: product does not properly track a count and a maximum number, which can lead to resultant array index overflow. • CVE-2007-5756: Chain: device driver for packet-capturing software allows access to an unintended IOCTL with resultant array index error. • CVE-2005-2456: Chain: array index error (CWE-129) leads to deadlock (CWE-833)

Related

Attack pattern · CAPEC (1)

Observed example · CVE (6)

  • CVE-2007-5756 Multiple array index errors in the bpf_filter_init function in NPF.SYS in WinPcap before 4.0.2, when run in monitor mode (aka Table… vulnerability
  • CVE-2005-2456 Array index overflow in the xfrm_sk_policy_insert function in xfrm_user.c in Linux kernel 2.6 allows local users to cause a denial of… vulnerability
  • CVE-2005-0369 Armagetron 0.2.6.0 and earlier and Armagetron Advanced 0.2.7.0 earlier allows remote attackers to cause a denial of service (application… vulnerability
  • CVE-2004-1189 The add_to_history function in svr_principal.c in libkadm5srv for MIT Kerberos 5 (krb5) up to 1.3.5, when performing a password change,… vulnerability
  • CVE-2003-0721 Integer signedness error in rfc2231_get_param from strings.c in PINE before 4.58 allows remote attackers to execute arbitrary code via an… vulnerability
  • CVE-2001-1009 Fetchmail (aka fetchmail-ssl) before 5.8.17 allows a remote malicious (1) IMAP server or (2) POP/POP3 server to overwrite arbitrary memory… vulnerability

Can precede · CWE (3)

  • CWE-119 Improper Restriction of Operations within the Bounds of a Memory Buffer weakness
  • CWE-789 Memory Allocation with Excessive Size Value weakness
  • CWE-823 Use of Out-of-range Pointer Offset weakness

Child of · CWE (2)

  • CWE-1285 Improper Validation of Specified Index, Position, or Offset in Input weakness
  • CWE-20 Improper Input Validation weakness

Referenced by CAPEC · weakness (1)

Referenced by CVE · weakness (695)

  • CVE-2026-119143 Wasmtime 46.0.0 before 48.0.6 and 49.0.0 before 49.0.3 contains a denial of service vulnerability that allows guest code to trigger a host… vulnerability
  • CVE-2024-58400 llama.cpp before b3701 contains an out-of-bounds read vulnerability in llama_decode_internal and llama_encode_internal that allows remote… vulnerability
  • CVE-2026-113881 A stack-based buffer overflow vulnerability in Fireware OS's VPN Network Access Enforcement process allows an authenticated mobile VPN user… vulnerability
  • CVE-2026-116816 llama.cpp b5899 before b10261 contains a heap out-of-bounds write vulnerability in llm_tokenizer_plamo2::build that allows attackers to… vulnerability
  • CVE-2026-93862 An out-of-bounds read vulnerability in the FireCluster Sync processing allows an attacker positioned on the cluster interconnect, such as a… vulnerability
  • CVE-2026-115916 vLLM is an inference and serving engine for large language models. vulnerability
  • CVE-2026-116585 Go JOSE provides an implementation of the Javascript Object Signing and Encryption set of standards in Go, including support for JSON Web… vulnerability
  • CVE-2026-116590 snappy-java is a Java port of the snappy, a fast C++ compresser/decompresser developed by Google. vulnerability
  • CVE-2026-116731 Furnace through 0.6.8.3 contains an out-of-bounds write vulnerability in DivEngine::loadFTM() that allows attackers to corrupt heap memory… vulnerability
  • CVE-2026-82945 SOEM version 2.0.0 and earlier contains a vulnerability during device configuration where a malicious device can cause memory corruption. vulnerability
  • CVE-2026-82947 SOEM version 2.0.0 and earlier contains multiple vulnerabilities in frame processing where a malicious device can cause the master to read… vulnerability
  • CVE-2026-116181 vLLM from 0.20.1 before 0.29.0 contains an improper input validation vulnerability that allows remote attackers to crash the engine by… vulnerability
  • CVE-2026-115722 RPly through 1.1.4 contains an improper array index validation vulnerability in ply_read_header_property() that accepts list as a list… vulnerability
  • CVE-2026-89319 `JweDirectDecryptorBlock.Decrypt` read a 64-bit plaintext length from the `_thales_aad` protected-header field and used it without any… vulnerability
  • CVE-2026-114405 Improper validation of array index vulnerability in Velneo vServer. vulnerability
  • CVE-2026-103672 The PEAK-System PCAN parser indexes a length table using attacker-controlled DLC without enforcing DLC <= 0x0f, then copies attacker… vulnerability
  • CVE-2026-92449 `_gx_binres_pixelmap_table_load()` in the GUIX binary resource (theme) loader indexes the pixelmap table with a value read verbatim from… vulnerability
  • CVE-2026-48741 libIEC61850 is an open-source implementation of IEC 61850 client and server protocols including MMS, GOOSE, Sampled Values, and R-Session. vulnerability
  • CVE-2026-110934 Improper validation of array index vulnerability in Samsung Open Source Vyond allows Input Data Manipulation. vulnerability
  • CVE-2026-92152 F´ (F Prime) is a framework that enables development and deployment of spaceflight and other embedded software applications. vulnerability
  • CVE-2026-77375 SFTPGo is an open source, event-driven file transfer solution. vulnerability
  • CVE-2026-109250 FreeRDP 3.0.0 before 3.32.0 contains a heap buffer overflow vulnerability in collect_keys() that allows local attackers to write past the… vulnerability
  • CVE-2026-109251 FreeRDP before 3.32.0 stores the server-supplied signed MS-RDPEGT geometry origin unchecked in an unsigned video surface coordinate, so the… vulnerability
  • CVE-2026-103220 The Affinity by Canva application before 3.3.1 (October 2026 release) did not perform adequate bounds checking when parsing raster image… vulnerability
  • CVE-2026-107325 Improper validation of a BSON array length in the MongoDB Go Driver can cause an out-of-bounds index and runtime panic when an application… vulnerability
  • CVE-2026-107737 SumatraPDF is a multi-format reader for Windows. vulnerability
  • CVE-2026-107211 Excelize is a Go language library for reading and writing Microsoft Excel spreadsheets. vulnerability
  • CVE-2026-107217 Excelize is a Go language library for reading and writing Microsoft Excel spreadsheets. vulnerability
  • CVE-2026-107218 Excelize is a Go language library for reading and writing Microsoft Excel spreadsheets. vulnerability
  • CVE-2026-107220 Excelize is a Go language library for reading and writing Microsoft Excel spreadsheets. vulnerability
Show all 695 ›

Referenced by CWE · has member (3)

  • CWE-1340 CISQ Data Protection Measures view
  • CWE-1460 Weaknesses Addressed by the Top 20 Secure PLC Coding Practices view
  • CWE-884 CWE Cross-section view

Referenced by OWASP · mapped cwe (1)