Fix expending buffer in StdCopy

Fixes #4851
ping @vieux