From 5f6ade8db9226633c7a8bf53e6fbe69d84916070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:36:12 +0400 Subject: [PATCH] Peer ID was erased if it contained non-latin characters (#1185) --- bt/announce.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bt/announce.php b/bt/announce.php index 101e5cd02..e9f1ff1ed 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -80,14 +80,14 @@ if (!isset($info_hash)) { } // Store info hash in hex format -$info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash); +$info_hash_hex = bin2hex($info_hash); // Store peer id -$peer_id_sql = rtrim(DB()->escape(htmlCHR($peer_id)), ' '); +$peer_id_sql = rtrim(DB()->escape(preg_replace('/[^a-zA-Z0-9\-\_\.]/', '', $peer_id)), ' '); // Check info_hash length if (strlen($info_hash) !== 20) { - msg_die('Invalid info_hash: ' . $info_hash_hex); + msg_die('Invalid info_hash: ' . (mb_check_encoding($info_hash, 'UTF8') ? $info_hash : $info_hash_hex)); } if (!isset($port) || $port < 0 || $port > 0xFFFF) { @@ -390,12 +390,13 @@ if (!$output) { // Retrieve peers $numwant = (int)$bb_cfg['tracker']['numwant']; $compact_mode = ($bb_cfg['tracker']['compact_mode'] || !empty($compact)); + $priority = $seeder ? 'seeder ASC, RAND()' : 'RAND()'; $rowset = DB()->fetch_rowset(" SELECT ip, ipv6, port FROM " . BB_BT_TRACKER . " WHERE topic_id = $topic_id - ORDER BY seeder ASC, RAND() + ORDER BY $priority LIMIT $numwant ");