Yeah, those char arrays are enormous. You either need to allocate the arrays on the heap, as static objects or increase the size of the stack. On most machines, the stack is not usually more than 1 or 2 megabytes by default.
You can make them static simply by declaration:
static char data[1000*1024];
static char chunk[2*1000*1024+1];
static char query[1024*5000];
To allocate them on the heap, you will need to rewrite the code a little. Hopefully you know how to do that.
To increase the stack size, you do this for the main executable project. Details are straightforward but slightly different for each version of Visual Studio.