Index: Math.php
===================================================================
--- Math.php	(revision 20875)
+++ Math.php	(working copy)
@@ -157,8 +157,8 @@
 				$dbw = wfGetDB( DB_MASTER );
 				$dbw->replace( 'math', array( 'math_inputhash' ),
 				  array(
-					'math_inputhash' => $md5_sql,
-					'math_outputhash' => $outmd5_sql,
+					'math_inputhash' => utf8_encode($md5_sql),
+					'math_outputhash' => utf8_encode($outmd5_sql),
 					'math_html_conservativeness' => $this->conservativeness,
 					'math_html' => $this->html,
 					'math_mathml' => $this->mathml,
@@ -186,7 +186,7 @@
 		$dbr = wfGetDB( DB_SLAVE );
 		$rpage = $dbr->selectRow( 'math',
 			array( 'math_outputhash','math_html_conservativeness','math_html','math_mathml' ),
-			array( 'math_inputhash' => pack("H32", $this->md5)), # Binary packed, not hex
+			array( 'math_inputhash' => utf8_encode(pack("H32", $this->md5))), # Binary packed, not hex
 			$fname
 		);
 
