RevisionStore: fail on mismatching hash or size.
The SlotRecord passed to RevisionStore::insertRevisionOn may have its sha1 and size already set by the caller. This is useful when restoring archived re visions, but apparently sometimes goes wrong, leading to a revision being recorded with the hash and size of its parent revision. This patch introduces a sanity check that ensures that the revision's hash and size matches the main slot's hash and size. If there are additional slots, the check is skipped. This does not fix the bug as reported, but should prevent any new revisions to be inserted with mismatching meta-data, and provide us with a stack trace that should help with finding the original cause of the issue. Bug: T239717 Change-Id: I4947731364925fef1c77cabcfd144fd2c07bf9db
This commit is contained in:
parent
ba673731d0
commit
9a7990dea9
2 changed files with 35 additions and 0 deletions
|
|
@ -467,6 +467,20 @@ class RevisionStore
|
|||
throw new IncompleteRevisionException( 'Revision is incomplete' );
|
||||
}
|
||||
|
||||
if ( $slotRoles == [ SlotRecord::MAIN ] ) {
|
||||
// T239717: If the main slot is the only slot, make sure the revision's nominal size
|
||||
// and hash match the main slot's nominal size and hash.
|
||||
$mainSlot = $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
|
||||
Assert::precondition(
|
||||
$mainSlot->getSize() === $rev->getSize(),
|
||||
'The revisions\'s size must match the main slot\'s size (see T239717)'
|
||||
);
|
||||
Assert::precondition(
|
||||
$mainSlot->getSha1() === $rev->getSha1(),
|
||||
'The revisions\'s SHA1 hash must match the main slot\'s SHA1 hash (see T239717)'
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: we shouldn't need an actual Title here.
|
||||
$title = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
|
||||
$pageId = $this->failOnEmpty( $rev->getPageId(), 'rev_page field' ); // check this early
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use TestUserRegistry;
|
|||
use Title;
|
||||
use User;
|
||||
use WANObjectCache;
|
||||
use Wikimedia\Assert\PreconditionException;
|
||||
use Wikimedia\Rdbms\Database;
|
||||
use Wikimedia\Rdbms\DatabaseDomain;
|
||||
use Wikimedia\Rdbms\DatabaseSqlite;
|
||||
|
|
@ -558,6 +559,26 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
|
|||
],
|
||||
new IncompleteRevisionException( 'user must not be NULL!' )
|
||||
];
|
||||
yield 'size mismatch' => [
|
||||
[
|
||||
'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
|
||||
'comment' => $this->getRandomCommentStoreComment(),
|
||||
'timestamp' => '20171117010101',
|
||||
'user' => true,
|
||||
'size' => 123456
|
||||
],
|
||||
new PreconditionException( 'T239717' )
|
||||
];
|
||||
yield 'sha1 mismatch' => [
|
||||
[
|
||||
'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
|
||||
'comment' => $this->getRandomCommentStoreComment(),
|
||||
'timestamp' => '20171117010101',
|
||||
'user' => true,
|
||||
'sha1' => 'DEADBEEF',
|
||||
],
|
||||
new PreconditionException( 'T239717' )
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue