--- htdig/ExternalParser.cc.orig	Wed Jan  9 16:23:25 2002
+++ htdig/ExternalParser.cc	Thu Aug  1 14:11:07 2002
@@ -535,8 +535,15 @@ ExternalParser::parse(Retriever &retriev
 	{
 	    char	buffer[2048];
 	    int		length;
-	    while ((length = fread(buffer, 1, sizeof(buffer), input)) > 0)
+	    int		nbytes = config.Value("max_doc_size");
+	    while (nbytes > 0 &&
+			(length = fread(buffer, 1, sizeof(buffer), input)) > 0)
+	    {
+		nbytes -= length;
+		if (nbytes < 0)
+		    length += nbytes;
 		newcontent.append(buffer, length);
+	    }
 	}
     }
     fclose(input);
