MDL-79539 core: handling negative input to get the upper value

Co-authored-by: Alain Corbière <alain.corbiere@univ-lemans.fr>
This commit is contained in:
meirzamoodle 2023-10-02 14:00:36 +07:00
parent 9c4b38b8d5
commit 66e8bde8b3
3 changed files with 25 additions and 3 deletions

View File

@ -456,12 +456,27 @@ class address_manager {
* @return string The encoded binary data
*/
protected function pack_int($int) {
// If PHP environment is running on a 64-bit.
if (PHP_INT_SIZE === 8) {
$l = intdiv($int, pow(2, 32)); // 32-bit integer quotient.
$r = $int % pow(2, 32); // 32-bit integer remaining.
// Will be used to ensures that the result remains as a 32-bit unsigned integer and
// doesn't extend beyond 32 bits.
$notation = 0xffffffff;
if ($int < 0) {
// If the given integer is negative, set it to -1.
$l = -1;
} else {
// Otherwise, calculate the upper 32 bits of the 64-bit integer.
$l = ($int >> 32) & $notation;
}
// Calculate the lower 32 bits of the 64-bit integer.
$r = $int & $notation;
// Pack the values of $l (upper 32 bits) and $r (lower 32 bits) into a binary string format.
return pack('NN', $l, $r);
} else {
// Pack the values into a binary string format.
return pack('NN', 0, $int);
}
}

View File

@ -3601,5 +3601,12 @@ privatefiles,moodle|/user/files.php';
upgrade_main_savepoint(true, 2023091300.03);
}
if ($oldversion < 2023092900.01) {
// Delete datakey with datavalue -1.
$DB->delete_records('messageinbound_datakeys', ['datavalue' => '-1']);
// Main savepoint reached.
upgrade_main_savepoint(true, 2023092900.01);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2023092900.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2023092900.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.3beta+ (Build: 20230929)'; // Human-friendly version name