$OpenBSD: patch-toolkit_components_history_src_nsGlobalHistory_cpp,v 1.1 2006/01/23 12:34:06 wilfried Exp $
--- toolkit/components/history/src/nsGlobalHistory.cpp.orig	Sun Oct 23 14:55:54 2005
+++ toolkit/components/history/src/nsGlobalHistory.cpp	Tue Dec 20 21:45:57 2005
@@ -113,6 +113,11 @@ nsIPrefBranch* nsGlobalHistory::gPrefBra
 
 #define FIND_BY_AGEINDAYS_PREFIX "find:datasource=history&match=AgeInDays&method="
 
+// see bug #319004 -- clamp title and URL to generously-large but not too large
+// length
+#define HISTORY_URI_LENGTH_MAX 65536
+#define HISTORY_TITLE_LENGTH_MAX 4096
+
 // sync history every 10 seconds
 #define HISTORY_SYNC_TIMEOUT (10 * PR_MSEC_PER_SEC)
 //#define HISTORY_SYNC_TIMEOUT 3000 // every 3 seconds - testing only!
@@ -618,6 +623,9 @@ nsGlobalHistory::AddPageToDatabase(nsIUR
   rv = aURI->GetSpec(URISpec);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (URISpec.Length() > HISTORY_URI_LENGTH_MAX)
+     return NS_OK;
+
 #ifdef DEBUG_bsmedberg
   printf("AddURI: %s%s%s",
          URISpec.get(),
@@ -1110,7 +1118,7 @@ nsGlobalHistory::SetPageTitle(nsIURI *aU
   nsresult rv;
   NS_ENSURE_ARG_POINTER(aURI);
 
-  const nsAFlatString& titleString = PromiseFlatString(aTitle);
+  nsAutoString titleString(StringHead(aTitle, HISTORY_TITLE_LENGTH_MAX));
 
   // skip about: URIs to avoid reading in the db (about:blank, especially)
   PRBool isAbout;
@@ -1411,6 +1419,9 @@ nsGlobalHistory::HidePage(nsIURI *aURI)
   rv = aURI->GetSpec(URISpec);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (URISpec.Length() > HISTORY_URI_LENGTH_MAX)
+     return NS_OK;
+
 #ifdef DEBUG_bsmedberg
   printf("nsGlobalHistory::HidePage: %s\n", URISpec.get());
 #endif
@@ -1447,7 +1458,10 @@ nsGlobalHistory::MarkPageAsTyped(nsIURI 
   nsCAutoString spec;
   nsresult rv = aURI->GetSpec(spec);
   if (NS_FAILED(rv)) return rv;
-  
+ 
+  if (spec.Length() > HISTORY_URI_LENGTH_MAX)
+     return NS_OK;
+
   nsCOMPtr<nsIMdbRow> row;
   rv = FindRow(kToken_URLColumn, spec.get(), getter_AddRefs(row));
   if (NS_FAILED(rv)) {
