mattgodbolt / seasocks

Simple, small, C++ embeddable webserver with WebSockets support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Per-message deflate causes bad_alloc on message length of 0

cake4289 opened this issue · comments

The return code of ::deflate is not checked - it returns Z_BUF_ERROR when:

  • It has already processed data before; and
  • It is passed a buffer with a length of zero

This happens when sending a message (other than the first message) over a websocket with a size of 0.

Then, resizing the output vector to size() - 4, which is a huge number as size() is zero, throws a bad_alloc exception.

I believe following RFC 7692 7.2.1 to the letter would fix this:

   2.  If the resulting data does not end with an empty DEFLATE block
       with no compression (the "BTYPE" bits are set to 00), append an
       empty DEFLATE block with no compression to the tail end.

@cake4289 - Thanks for the bug report! Is it possible for you to send a pull request?

commented

Thanks @cake4289 for providing a fix that fast! 👍

@cake4289 - Great, thanks!