From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- includes/HistoryBlob.php | 64 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 11 deletions(-) (limited to 'includes/HistoryBlob.php') diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index f707b3f6..bb8ec5e3 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -1,5 +1,25 @@ mHash = $hash; @@ -298,7 +318,7 @@ class HistoryBlobCurStub { } /** - * @return string|false + * @return string|bool */ function getText() { $dbr = wfGetDB( DB_SLAVE ); @@ -515,13 +535,11 @@ class DiffHistoryBlob implements HistoryBlob { $header = unpack( 'Vofp/Vcsize', substr( $diff, 0, 8 ) ); - # Check the checksum if mhash is available - if ( extension_loaded( 'mhash' ) ) { - $ofp = mhash( MHASH_ADLER32, $base ); - if ( $ofp !== substr( $diff, 0, 4 ) ) { - wfDebug( __METHOD__. ": incorrect base checksum\n" ); - return false; - } + # Check the checksum if hash/mhash is available + $ofp = $this->xdiffAdler32( $base ); + if ( $ofp !== false && $ofp !== substr( $diff, 0, 4 ) ) { + wfDebug( __METHOD__. ": incorrect base checksum\n" ); + return false; } if ( $header['csize'] != strlen( $base ) ) { wfDebug( __METHOD__. ": incorrect base length\n" ); @@ -560,6 +578,30 @@ class DiffHistoryBlob implements HistoryBlob { return $out; } + /** + * Compute a binary "Adler-32" checksum as defined by LibXDiff, i.e. with + * the bytes backwards and initialised with 0 instead of 1. See bug 34428. + * + * Returns false if no hashing library is available + */ + function xdiffAdler32( $s ) { + static $init; + if ( $init === null ) { + $init = str_repeat( "\xf0", 205 ) . "\xee" . str_repeat( "\xf0", 67 ) . "\x02"; + } + // The real Adler-32 checksum of $init is zero, so it initialises the + // state to zero, as it is at the start of LibXDiff's checksum + // algorithm. Appending the subject string then simulates LibXDiff. + if ( function_exists( 'hash' ) ) { + $hash = hash( 'adler32', $init . $s, true ); + } elseif ( function_exists( 'mhash' ) ) { + $hash = mhash( MHASH_ADLER32, $init . $s ); + } else { + return false; + } + return strrev( $hash ); + } + function uncompress() { if ( !$this->mDiffs ) { return; -- cgit v1.2.2