Parsing would ignore the size of data already buffered, resulting in bad_alloc exception. Fixes #2898.
It contains client code as well.