In-depth lesson · Memory corruption
Typical fixes
Every point the Memory corruption reports back under this heading, best-backed first, each with the reports it is seen in.
-
Track ownership of the trial and best pointers so a failed iteration does not free the same memory twice.
-
Track which pages belong to which mapping when a queue is rebound so closing an old mapping does not free pages in use.
-
Treat a failed AMSI scan as suspicious rather than clean, and protect the AMSI context from tampering.
Seen in 1 report
-
Treat any negative decompressor return as an error and keep the size unsigned only after validation.
-
Treat incomplete input as invalid and stop processing after a block-type switch error.
Seen in 1 report
-
Treat negative width and height values as invalid before the size sanity check.
Seen in 1 report
-
Update local pointers after a realloc moves the buffer.
Seen in 1 report
-
Update the remaining length and invalidate the pointer when a buffer is freed during unmarshalling.
Seen in 1 report
-
Update the stale pointer after reallocating the buffer.
Seen in 1 report
-
Upgrade nginx to a version that fixes the chunked transfer-encoding stack buffer overflow.
Seen in 1 report
-
Use 64-bit arithmetic for the chroma plane size calculation.
Seen in 1 report
-
Use a flexible array member instead of a pointer array so the allocation fits the copied string.
-
Use a greater-or-equal comparison when checking an index against an array length.
Seen in 1 report
-
Use a reference count width that cannot overflow, or check for saturation before incrementing.
Seen in 1 report
-
Use a safe allowlist for classes that a JSON deserializer may instantiate.
Seen in 1 report
-
Use a wider integer or check for overflow when expanding the association group table.
Seen in 1 report
-
Use a zero base array layer for 3D texture copies and map the z offset correctly.
Seen in 1 report
-
Use bounded string copies and check input length against the fixed buffer in argument handling.
Seen in 1 report
-
Use bounded string copying and verify the host string length against the buffer size.
Seen in 1 report
-
Use checked arithmetic for the entry buffer size calculation.
Seen in 1 report
-
Use checked arithmetic when accumulating glyph counts.
Seen in 1 report
-
Use one less than the buffer size in the bounds check.
-
Use overflow-checked arithmetic when summing unpack stream counts.
Seen in 1 report
-
Use overflow-safe arithmetic in the precision bounds check.
-
Use overflow-safe bounds checks that cannot wrap around.
Seen in 1 report
-
Use the actual argument count in callbacks rather than fixed stack loads and cleanup.
Seen in 1 report
-
Use the actual source length rather than the destination buffer size in copy calls.
Seen in 1 report
-
Use the actual truncated length returned by the bounded string formatting call when sending the response.
Seen in 1 report
-
Use the correct comparison so a value equal to the buffer size is rejected.
Seen in 1 report
-
Use the destination buffer size rather than the input length when copying the title.
Seen in 1 report
-
Use the length prefix of the wide string instead of scanning for a null terminator.
Seen in 1 report
-
Use the request object for metrics before resolving the promise so user code cannot free it in between.
Seen in 1 report
-
Use the return value of readlink to set the real length instead of trusting the size from lstat.
Seen in 1 report
-
Use the same length variable for allocation and for the read.
Seen in 1 report
-
Use unsigned branch instructions when comparing the size parameter in memcpy.
Seen in 1 report
-
Use user-safe copy routines when writing to user-supplied addresses.
Seen in 1 report
-
Use weak references for the web state list in completion blocks and check for nil before dereferencing.
Seen in 1 report
-
Validate an annotation pointer after the object has been freed.
Seen in 1 report
-
Validate and clamp specification-defined field widths at IPC deserialisation rather than trusting the sender.
Seen in 1 report
-
Validate array indices from file headers against the parsed table range.
Seen in 1 report
-
Validate array indices taken from file data.
-
Validate B-record fields against the Type A grid dimensions before the write loop runs.
Seen in 1 report
-
Validate both x and y coordinates against the image dimensions before writing pixels.
Seen in 1 report
-
Validate bounding box coordinates and avoid truncating floating-point values to signed integers for loop counters.
Seen in 1 report
-
Validate client input length and count values before use in request parsing.
Seen in 1 report
-
Validate image dimensions before allocating memory for conversion.
Seen in 1 report
-
Validate input before use in the affected component.
-
Validate input lengths and pointers when parsing authentication tokens.
-
Validate neighbour vertex IDs against the declared vertex count before storing and using them as point indices.
Seen in 1 report
-
Validate node and element indices against the allocated bounds before indexing.
Seen in 1 report