we should try to have a range checked buffer here. I don't know the interface of doc.Parse, but if the buffer is a template, we could use the boost::autobuffer stuff or something similiar