Fix stack overflow in issue #456

cherry-picking 43396d39c8b9
fix another stack overflow error when parse large CDATA

cherry-picking 8c437298d52b7
add test for #456

cherry-picking fa77ace673c3b6