This should be buf.GetSize() -- the text.GetSize() is in UTF-8 bytes, which may not be correct for the UTF-16 data in buf...