Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MonoTorrent is unable to transmit files >2GB #657

Open
lostmsu opened this issue May 14, 2024 · 1 comment
Open

MonoTorrent is unable to transmit files >2GB #657

lostmsu opened this issue May 14, 2024 · 1 comment

Comments

@lostmsu
Copy link

lostmsu commented May 14, 2024

plz see pull request #656 for an end-to-end integration test

The first issue I am hitting is inability to create a v2 torrent (did not test v1) that would include such a file due to ArgumentOutOfRangeException:

IPieceWriterExtensions.ReadFromFilesAsync(IPieceWriter writer, ITorrentManagerInfo manager, BlockInfo request, Memory1 buffer) line 47 ReusableTaskAwaiter1.GetResult()
MemoryCache.ReadAsync(ITorrentManagerInfo torrent, BlockInfo block, Memory1 buffer) line 142 ReusableTaskAwaiter1.GetResult()
DiskManager.ReadAsync(ITorrentManagerInfo manager, BlockInfo request, Memory1 buffer) line 490 ReusableTaskAwaiter1.GetResult()
DiskManager.GetHashAsync(ITorrentManagerInfo manager, Int32 pieceIndex, PieceHash dest) line 375
DiskManager.GetHashAsync(ITorrentManagerInfo manager, Int32 pieceIndex, PieceHash dest) line 399
ReusableTaskAwaiter`1.GetResult()
TorrentCreator.CalcPiecesHash(ITorrentManagerInfo manager, CancellationToken token) line 424
TorrentCreator.CreateAsync(String name, ITorrentFileSource fileSource, CancellationToken token) line 294
TorrentCreator.CreateAsync(ITorrentFileSource fileSource, CancellationToken token) line 241
IntegrationTestsBase.CreateAndDownloadTorrent(TorrentType torrentType, Boolean createEmptyFile, Boolean explitlyHashCheck, Int32 nonEmptyFileCount, Boolean useWebSeedDownload, Int64 fileSize) line 197
IntegrationTestsBase.DownloadFileInTorrent_V2_Empty_And_BigNonEmpty() line 113

I have my own fork where I replaced a few ints and floating point math with longs: lostmsu@08893f7 , but even with that fix for some reason creating a torrent succeeds, but when attempting to seed >2GB files fail hash check.

@lostmsu
Copy link
Author

lostmsu commented May 14, 2024

FYI, the abovementioned commit 08893f7 has a couple of critical bugs in IntMath (to put it mildly 😁). It should look like this instead:

using System;

namespace MonoTorrent
{
    static class IntMath
    {
        public static long PowUnchecked (long value, int power)
        {
            if (power < 0)
                throw new ArgumentOutOfRangeException (nameof (power), "Power must be greater than or equal to zero");
            if (power == 0)
                return 1;
            return (power & 1) == 0
                ? PowUnchecked (value * value, power >> 1)
                : value * PowUnchecked (value, power - 1);
        }

        public static long Pow (long value, int power)
        {
            if (power < 0)
                throw new ArgumentOutOfRangeException (nameof (power), "Power must be greater than or equal to zero");
            if (power == 0)
                return 1;
            return checked((power & 1) == 0
                ? Pow (value * value, power >> 1)
                : value * Pow (value, power - 1));
        }

        public static int Pow (int value, int power)
        {
            if (power < 0)
                throw new ArgumentOutOfRangeException (nameof (power), "Power must be greater than or equal to zero");
            if (power == 0)
                return 1;
            return checked((power & 1) == 0
                ? Pow (value * value, power >> 1)
                : value * Pow (value, power - 1));
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant