Why is buffer received over USB is not aligned on transmitted buffer length?
Fundamentally, a USB connection is just a stream of bytes. There is no guarantee that a buffer used at one end corresponds to a buffer used at the other end. Your data needs to be formatted to live within this restriction, with some unambiguous in-band protocol to indicate message boundaries.

Furthermore, you need to make sure you check the value of lpNumberOfBytesRead BEFORE you try to do anything with the data &mdash; including searching for boundary flags. It could be anything between 0 and nNumberOfBytesToRead.