SF bug #1054139:  serious string hashing error in 2.4b1

_PyString_Resize() readied strings for mutation but did not invalidate
the cached hash value.
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 4335965..c8ed07c 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -80,6 +80,15 @@
         args = self.fixtype(args)
         getattr(object, methodname)(*args)
 
+    def test_hash(self):
+        # SF bug 1054139:  += optimization was not invalidating cached hash value
+        a = self.type2test('DNSSEC')
+        b = self.type2test('')
+        for c in a:
+            b += c
+            hash(b)
+        self.assertEqual(hash(a), hash(b))
+
     def test_capitalize(self):
         self.checkequal(' hello ', ' hello ', 'capitalize')
         self.checkequal('Hello ', 'Hello ','capitalize')
diff --git a/Misc/NEWS b/Misc/NEWS
index e5437e1..6c0935e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,7 +32,7 @@
 Core and builtins
 -----------------
 
-...
+- Bug #1054139 _PyString_Resize() now invalidates its cached hash value.
 
 Extension Modules
 -----------------
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index c87b688..b8e5f41 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3530,6 +3530,7 @@
 	sv = (PyStringObject *) *pv;
 	sv->ob_size = newsize;
 	sv->ob_sval[newsize] = '\0';
+	sv->ob_shash = -1;	/* invalidate cached hash value */
 	return 0;
 }