1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 16:24:02 +00:00

test: fuzz test tr_magnet_metainfo.parseMagnet() (#2890)

This commit is contained in:
Charles Kerr 2022-04-06 13:22:08 -05:00 committed by GitHub
parent eb33b2faf5
commit e88ebbc3e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 6 deletions

View file

@ -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 {};
}

View file

@ -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) }));
}
}