mirror of
https://github.com/transmission/transmission
synced 2024-12-24 00:34:04 +00:00
test: fuzz test tr_magnet_metainfo.parseMagnet() (#2890)
This commit is contained in:
parent
eb33b2faf5
commit
e88ebbc3e5
2 changed files with 36 additions and 6 deletions
|
@ -119,7 +119,7 @@ std::optional<tr_sha1_digest_t> parseBase32Hash(std::string_view sv)
|
|||
std::begin(sv),
|
||||
std::end(sv),
|
||||
[](unsigned char ch)
|
||||
{ return '0' <= ch && ch <= '0' + std::size(bitzi::Base32Lookup) && bitzi::Base32Lookup[ch - '0'] != 0xFF; }))
|
||||
{ return '0' <= ch && ch < '0' + std::size(bitzi::Base32Lookup) && bitzi::Base32Lookup[ch - '0'] != 0xFF; }))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -3,14 +3,16 @@
|
|||
// or any future license endorsed by Mnemosyne LLC.
|
||||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include "transmission.h"
|
||||
#include "magnet-metainfo.h"
|
||||
#include "utils.h"
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
#include "transmission.h"
|
||||
|
||||
#include "crypto-utils.h"
|
||||
#include "magnet-metainfo.h"
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
|
@ -89,3 +91,31 @@ TEST(MagnetMetainfo, magnetParse)
|
|||
EXPECT_EQ(ExpectedHash, mm.infoHash());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WebUtilsTest, parseMagnetFuzzRegressions)
|
||||
{
|
||||
auto buf = std::vector<char>{};
|
||||
|
||||
static auto constexpr Tests = std::array<std::string_view, 1>{
|
||||
"UICOl7RLjChs/QZZwNH4sSQwuH890UMHuoxoWBmMkr0=",
|
||||
};
|
||||
|
||||
for (auto const& test : Tests)
|
||||
{
|
||||
auto mm = tr_magnet_metainfo{};
|
||||
mm.parseMagnet(tr_base64_decode(test));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(WebUtilsTest, parseMagnetFuzz)
|
||||
{
|
||||
auto buf = std::vector<char>{};
|
||||
|
||||
for (size_t i = 0; i < 100000; ++i)
|
||||
{
|
||||
buf.resize(tr_rand_int(1024));
|
||||
tr_rand_buffer(std::data(buf), std::size(buf));
|
||||
auto mm = tr_magnet_metainfo{};
|
||||
EXPECT_FALSE(mm.parseMagnet({ std::data(buf), std::size(buf) }));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue