Fix for bug #1990430.
diff --git a/expat/lib/xmltok_impl.c b/expat/lib/xmltok_impl.c
index 1268819..b71410d 100644
--- a/expat/lib/xmltok_impl.c
+++ b/expat/lib/xmltok_impl.c
@@ -1748,6 +1748,8 @@
     switch (BYTE_TYPE(enc, ptr)) {
 #define LEAD_CASE(n) \
     case BT_LEAD ## n: \
+      if (end - ptr < n) \
+        return; \
       ptr += n; \
       break;
     LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4)