>I increase the value of messagebuf past 8MB, I get a segmentation fault when I execute it regardless of the size of the input file.
Based on Steven's comments about stack size, if the stack grows towards 0, then the first byte you put into the array will be beyond the top of the stack.