Skip to content

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.

Back to the lesson 1 to 50 of 976
  1. Validate the length of supplied data against the destination buffer size before copying.

    Seen in 113 reports
  2. Apple fixed most of these with improved bounds checking, improved input validation or improved memory management.

    Seen in 82 reports
  3. Validate that an object still exists before dereferencing or operating on it, and close race windows between freeing and reuse.

    Seen in 76 reports
  4. Add bounds and length checks before copying input into fixed-size buffers.

    Seen in 68 reports
  5. Add correct length and bounds checks before writing to heap or stack buffers.

    Seen in 68 reports
  6. Validate input length and size before any copy into a heap or stack buffer, and reject values that exceed the destination.

    Seen in 67 reports
  7. Validate the length of user-supplied data before copying it into a fixed stack buffer.

    Seen in 65 reports
  8. Validate declared lengths against the destination buffer size before reading or writing.

    Seen in 57 reports
  9. Validate lengths and sizes against the destination buffer before copying data into it.

    Seen in 57 reports
  10. Add bounds checks before reading or writing file-derived data.

    Seen in 56 reports
  11. Validate length, size and offset fields against the destination buffer before copying or reading.

    Seen in 56 reports
  12. Check that an object still exists before operating on it.

    Seen in 52 reports
  13. Use reference counting and safe teardown so objects cannot be freed while another thread still holds a reference, and guard against double free.

    Seen in 50 reports
  14. Validate the length of network and file input before copying it into fixed-size or heap buffers.

    Seen in 45 reports
  15. Check that an object still exists before operating on it, and clear pointers after freeing.

    Seen in 40 reports
  16. Check that an object still exists before using or freeing it, and clear pointers after freeing.

    Seen in 40 reports
  17. Check that an object still exists before operating on it, and clear references when freeing.

    Seen in 37 reports
  18. Validate the length of user-supplied data before copying it into fixed-size buffers.

    Seen in 36 reports
  19. Fix object lifetime handling so memory is not accessed after being freed, including under race conditions.

    Seen in 33 reports
  20. Fix object lifetime handling so memory is not freed twice or used after release, including under races.

    Seen in 33 reports
  21. Add bounds checks before reading or writing user-supplied data.

    Seen in 32 reports
  22. Use reference counting or deferred reclamation so objects cannot be freed while still reachable.

    Seen in 32 reports
  23. Fix object lifetime handling so memory is not freed while still referenced, and close the timing window that a race condition needs.

    Seen in 31 reports
  24. Use weak pointers or synchronisation barriers so asynchronous callbacks and cancellation paths cannot use an object after it is freed.

    Seen in 31 reports
  25. Check the size and structure of input data against the destination buffer before reading or writing.

    Seen in 30 reports
  26. Fix reference counting and lifetime handling so freed objects are not reused, and close race windows.

    Seen in 30 reports
  27. Validate every size, length and offset field against the destination buffer before copying or writing.

    Seen in 30 reports
  28. Validate that user-supplied values point to valid, expected memory before dereferencing them.

    Seen in 25 reports
  29. Fix object lifetime handling so freed memory is not referenced again and is not freed twice.

    Seen in 24 reports
  30. Manage object lifetime so freed memory is not referenced again, including under concurrency.

    Seen in 23 reports
  31. Validate all size, length and offset fields against the destination buffer before reading or writing.

    Seen in 23 reports
  32. Validate the size and structure of user-supplied data before reading or writing it.

    Seen in 22 reports
  33. Validate every size and length against the destination buffer before copying, and check read lengths against allocations.

    Seen in 21 reports
  34. Add bounds checks before reading from a buffer parsed from untrusted input.

    Seen in 20 reports
  35. Check that an object still exists before using or freeing it again.

    Seen in 20 reports
  36. Check user-supplied counts and sizes for overflow before using them in allocation size calculations.

    Seen in 20 reports
  37. Add bounds checks before writing document-controlled sizes into heap and stack buffers.

    Seen in 19 reports
  38. Check that an object still exists before using it, and clear or invalidate pointers when objects are freed.

    Seen in 19 reports
  39. Check the length of input before copying it into a fixed-size buffer.

    Seen in 19 reports
  40. Check that an object still exists before operating on it, and clear stale pointers after freeing.

    Seen in 18 reports
  41. Replace debug-only assertions that guard security-relevant bounds or type assumptions with checks that remain in release builds.

    Seen in 18 reports
  42. Validate every length, size, count and offset read from a file against the destination buffer before copying or indexing.

    Seen in 18 reports
  43. Add bounds checks before reading data so code cannot read past the end of a buffer.

    Seen in 17 reports
  44. Fix object lifetime handling so freed memory is not referenced, and make the relevant operations atomic to close race windows.

    Seen in 17 reports
  45. Check arithmetic on user-supplied sizes for overflow, underflow and truncation before allocating or copying.

    Seen in 16 reports
  46. Check input length against the destination buffer size before copying into heap or stack buffers.

    Seen in 16 reports
  47. Check the length of user-supplied data before copying it into fixed-size stack or heap buffers.

    Seen in 16 reports
  48. Validate every count, offset and size field against the record size before using it to index or copy.

    Seen in 16 reports
  49. Validate the length and bounds of user-supplied data before copying or indexing it.

    Seen in 15 reports
  50. Validate the length of user-supplied data against the destination buffer before every copy, and check size calculations for overflow.

    Seen in 15 reports