Memory corruption

Short description: Type of software bug

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)

This article possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (June 2020) (Learn how and when to remove this template message)

|

(Learn how and when to remove this template message)

Program execution

General concepts

* Code
* Translation
* Compiler
* Compile-time
* Optimizing compiler
* Intermediate representation (IR)
* Execution
* Runtime system
* Runtime
* Executable
* Interpreter
* Virtual machine

Types of code

* Source code
* Object code
* Bytecode
* Machine code
* Microcode

Compilation strategies

* Just-in-time (JIT)
* Tracing just-in-time
* Ahead-of-time (AOT)
* Transcompilation
* Recompilation

Notable runtimes

* Android Runtime (ART)
* Common Language Runtime (CLR) & Mono
* crt0
* HHVM
* Java virtual machine (JVM)
* Objective-C
* V8
* Node.js
* PyPy
* Zend Engine

Notable compilers & toolchains

* GNU Compiler Collection (GCC)
* LLVM
* Clang

* v
* t
* e

Memory corruption occurs in a computer program when the contents of a memory location are modified due to programmatic behavior that exceeds the intention of the original programmer or program/language constructs; this is termed as violation of memory safety. The most likely causes of memory corruption are programming errors (software bugs). When the corrupted memory contents are used later in that program, it leads either to program crash or to strange and bizarre program behavior. Nearly 10% of application crashes on Windows systems are due to heap corruption.[1]

Modern programming languages like C and C++ have powerful features of explicit memory management and pointer arithmetic. These features are designed for developing efficient applications and system software. However, using these features incorrectly may lead to memory corruption errors.

Memory corruption is one of the most intractable class of programming errors, for two reasons:

1. The source of the memory corruption and its manifestation may be far apart, making it hard to correlate the cause and the effect.
2. Symptoms appear under unusual conditions, making it hard to consistently reproduce the error.

Memory corruption errors can be broadly classified into four categories:

1. Using uninitialized memory: Contents of uninitialized memory are treated as garbage values. Using such values can lead to unpredictable program behavior.
2. Using non-owned memory: It is common to use pointers to access and modify memory. If such a pointer is a null pointer, dangling pointer (pointing to memory that has already been freed), or to a memory location outside of current stack or heap bounds, it is referring to memory that is not then possessed by the program. Using such pointers is a serious programming flaw. Accessing such memory usually causes operating system exceptions, that most commonly lead to a program crash (unless suitable memory protection software is being used).
3. Using memory beyond the memory that was allocated (buffer overflow): If an array is used in a loop, with incorrect terminating condition, memory beyond the array bounds may be accidentally manipulated. Buffer overflow is one of the most common programming flaws exploited by computer viruses, causing serious computer security issues (e.g. return-to-libc attack, stack-smashing protection) in widely used programs. In some cases programs can also incorrectly access the memory before the start of a buffer.
4. Faulty heap memory management: Memory leaks and freeing non-heap or un-allocated memory are the most frequent errors caused by faulty heap memory management.

Many memory debuggers such as Purify, Valgrind, Insure++, Parasoft C/C++test, AddressSanitizer are available to detect memory corruption errors.

## See also

* Storage violation

## References

1. ↑ Radich, Q.; Sherer, T.; Sharkey, K.; Batchelor, D.; Kennedy, J. T.; Mabee, D.; Coulter, D.; Michael, S. (28 April 2021). "Application Verifier (Windows 7 and Windows Server 2008 R2 Application Quality Cookbook) - Win32 apps" (in en-us). Microsoft Developer Network. https://docs.microsoft.com/en-us/windows/win32/win7appqual/application-verifier.

## External links

* Memory Corruption Tutorial An introduction to exploitation techniques and protection mechanisms

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Memory corruption. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Memory_corruption&oldid=4227787"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template