Significantly simplified bounds check by marking end of doc with zero byte