Merge "Handle a negative exponent in TempUser/ScrambleMapping.php"

This commit is contained in:
jenkins-bot 2024-01-02 06:33:46 +00:00 committed by Gerrit Code Review
commit 2d5499a89a
2 changed files with 10 additions and 0 deletions

View file

@ -76,6 +76,9 @@ class ScrambleMapping implements SerialMapping {
return (string)$index;
}
$offset = $this->offset;
if ( $index - $offset < 0 ) {
throw new \MWException( __METHOD__ . ": The configured offset $offset is too large." );
}
foreach ( self::GENERATORS as [ $g, $p ] ) {
if ( $index - $offset < $p ) {
return (string)( $offset + $this->powmod( $g, $index - $offset, $p ) );

View file

@ -3,6 +3,7 @@
namespace MediaWiki\Tests\User\TempUser;
use MediaWiki\User\TempUser\ScrambleMapping;
use MWException;
use PHPUnit\Framework\TestCase;
/**
@ -31,4 +32,10 @@ class ScrambleMappingTest extends TestCase {
}
$this->assertSame( 0, $duplicates, 'duplicate detected' );
}
public function testOffsetTooLarge() {
$map = new ScrambleMapping( [ 'offset' => 10 ] );
$this->expectException( MWException::class );
$map->getSerialIdForIndex( 1 );
}
}