please fix the HEAP CORRUPTION DETECTED error

Feb 9, 2021 at 7:28pm
I run a growtopia private server and have been recently getting server crashes
due to HEAP CORRUPTION DETECTED error when joining certain worlds.

The code is here on pastebin: https://pastebin.com/QqwqjusB
can someone please fix the issue and reupload to a new paste?

it would be incredibly helpful as my main coder is in the hospital and I don't understand c++ good at all....
Feb 9, 2021 at 7:32pm
If the array only has a size of 69 bytes, then surely lines like
1
2
3
4
5
        memcpy(data + 66, &loled, 4);
        memcpy(data + 68, &state, 4);

        memcpy(data + 67, &yeetus, 5);
        memcpy(data + 68, &state, 4);

are all going out of bounds.

Also, you should delete[] a new[]'d array, not just delete.
i.e. delete[] data;

Btw, I assume some sort of clean up is needed to free the data presumably created by the enet_packet_create call.

That code looks as if a troll made it.
Last edited on Feb 10, 2021 at 2:17pm
Feb 9, 2021 at 8:49pm
> memcpy(data + 67, &yeetus, 5);
> memcpy(data + 68, &state, 4);
You have some very strange offsets and lengths.

First, let's assume that int's are 4 bytes on your machine, and that the endians of the peer machines is the same (see https://en.wikipedia.org/wiki/Endianness )

So,
1 - yeetus is only 4 bytes, but you copy 5
2 - you lose most of yeetus when you overwrite it with state

EDIT:
It's 4 (FOUR) not 5 - meh, thanks ne555
Last edited on Feb 10, 2021 at 5:10pm
Feb 10, 2021 at 4:49pm
> Also, you should delete[] a new[]'d array,
or, as the size is known at compile time, don't use dynamic memory allocation
BYTE data[69];

> yeetus is only 5 bytes, but you copy 5
¿? ¿why that would be a problem?
Feb 10, 2021 at 5:01pm
It looks like data is the data portion of a packet of some sort. Do you know the format of that packet? Without knowing what the format is supposed to be, it's hard to know how to fix the problems.
Topic archived. No new replies allowed.