Validate UTF8 in xmlEncodeEntities

Code is currently assuming UTF-8 without validating. Truncated UTF-8
input can cause out-of-bounds array access.

Adds further checks to partial fix in 50f06b3e.

Fixes #178
4 jobs for master in 17 minutes and 18 seconds
Status Name Job ID Coverage
  Test
passed clang:asan #1264296

00:04:36

passed cmake:mingw:w64-x86_64:shared #1264297
win32-ps

00:03:12

passed cmake:msvc:v141:x64:shared #1264298
win32-ps

00:10:03

passed gcc #1264295

00:02:55