Exception handling for Bencode errors (#1239)

This commit is contained in:
Cønstantine Kovalensky 2023-12-20 21:46:49 +04:00 committed by GitHub
commit 586fc0b563
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 7 deletions

View file

@ -30,9 +30,9 @@ if (!file_exists($filename) || !$file_contents = file_get_contents($filename)) {
try { try {
$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY);
} } catch (Exception) {
catch (Exception) { $this->response['html'] = $lang['TORFILE_INVALID'];
return $lang['TORFILE_INVALID']; return;
} }
$torrent = new TorrentPier\Legacy\TorrentFileList($tor); $torrent = new TorrentPier\Legacy\TorrentFileList($tor);

View file

@ -62,8 +62,7 @@ if ($bb_cfg['flist_max_files']) {
try { try {
$torrent = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); $torrent = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY);
} } catch (Exception) {
catch (Exception) {
http_response_code(410); http_response_code(410);
die($lang['TORFILE_INVALID']); die($lang['TORFILE_INVALID']);
} }

View file

@ -564,8 +564,7 @@ class Torrent
$file_contents = file_get_contents($filename); $file_contents = file_get_contents($filename);
try { try {
$tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY); $tor = \Arokettu\Bencode\Bencode::decode($file_contents, dictType: \Arokettu\Bencode\Bencode\Collection::ARRAY);
} } catch (Exception) {
catch (Exception) {
bb_die($lang['TORFILE_INVALID']); bb_die($lang['TORFILE_INVALID']);
} }