The crash is not coming because you are reading invalid / undefined memory, it is coming because you passed an invalid buffer into ReadProcessMemory
. Note that the the error message says violation writing, not reading.
You need to make sure the buffer you are passing is appropriately sized for the data amount that you are requesting. If you post the code used to call the method we may be able to help spot the error