diff --git a/src/modules/spider/xml.c b/src/modules/spider/xml.c
index 4dadef1212e63a64a174eb3056f2931f3f1999b6..9156c8044ed58cfdb5bdea5986775f0134608bc3 100644
--- a/src/modules/spider/xml.c
+++ b/src/modules/spider/xml.c
@@ -1338,7 +1338,7 @@ static void simple_read_attributes(struct xmldata *data,
   SKIPSPACE();
   
   /* Read unordered attributes */
-  while(isFirstNameChar(PEEK(0)))
+  while(data->input.len>0 && isFirstNameChar(PEEK(0)))
   {
     int iscd;
     SIMPLE_READNAME();
@@ -1828,6 +1828,7 @@ static int really_low_parse_dtd(struct xmldata *data)
 			  while(PEEK(0)=='|')
 			  {
 			    READ(1);
+			    SKIPSPACE();
 			    SIMPLE_READNAME();
 			    SKIPSPACE();
 			    check_stack(1);