Fix the internal buffer sizing. Thanks to Sudheer for helping isolating this bug