433692 improved buffer resizing

(cherry picked from commit 2e261b75d6dd749b5ea354e16750c64b81faa42c)