Important: Please read the Qt Code of Conduct -

[SOLVED]Application terminates->*** buffer overflow detected ***

  • I have developed one application which establishes QTCPSocket connection with windows server. Initially server sends around 30,000 bytes of data. which my application is not able to read in one go.
    Data is coming in chunks like first 2048 byets followed by 15000 bytes and then complete dtaa.
    In case if data is not completely received then I am not reading it from socket buffer, thereby using the socket buffer itself to store the data till I get complete.

    But in this case when I get data in chunks , my app is terminating , and I am getting error on console saying that
    *** buffer overflow detected ***.

    OS :- Open Suse 11.2 SP2
    Qt : - 4.6.2

    Please help what shall I do to avoid this.
    Note :- I tried below mention options also but no help

  • This is a classic problem when using sockets, and nothing specific to Qt or C++ as such.

    The only solution is that you have to read the multiple chuncks and append them in your application. Basically you have to end up writing a simple application layer protocol.

  • The TCP protocol provides a "byte stream" abstraction. Even though that "stream" has to be transferred in limited-size IP packets on the lower layers, (and will be reassembled on the receiver's side), at the TCP-level you just have a continuous byte stream. Thus, you cannot expect that the "chunks" of bytes that pop out of the TCP connection are the same size and/or number as the chunks of bytes that the sender has pushed into the TCP connection. All you know is that all bytes will be delivered - eventually. In the correct order, but in chunks of arbitrary size. Consequently you won't get around appending all the "chunks" of data that you get from the TCP connection inside your own separate buffer. Also, you will have to decide yourself when a specific "message" (block of data) ends. That's why protocols based on TCP, such as HTTP, usually send a small header first. That header, besides other info, also contains the number of bytes that will follow until the "message" is complete.

  • Thanks a lot guyz for your response.I put a proper buffering mechanism at my client place and I got rid of this problem.

Log in to reply