question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty file in torrent causes infinite loop

See original GitHub issue

Creating a v2 torrent from a folder with an empty file causes an infinite loop in MerkleHash.TryHash() because src.Length == 0. This test repros the problem in master and release-v3.0.0-beta-0034.

[TestFixture]
public class EmptyFileInTorrentTests
{
    [Test]
    public void EmptyFileInTorrent ()
    {
        var dir = new DirectoryInfo ("Data");
        if (!dir.Exists)
            dir.Create ();

        var emptyFile = new FileInfo (Path.Combine (dir.FullName, "Empty.file"));
        File.WriteAllText (emptyFile.FullName, "");

        var nonEmptyFile = new FileInfo (Path.Combine (dir.FullName, "NonEmpty.file"));
        File.WriteAllText (nonEmptyFile.FullName, "aoeuaoeu");

        emptyFile.Refresh ();
        Assert.AreEqual (0, emptyFile.Length);

        ITorrentFileSource fileSource = new TorrentFileSource (dir.FullName);
        TorrentCreator torrentCreator = new TorrentCreator (TorrentType.V1V2Hybrid);
        var creationTask = torrentCreator.CreateAsync (fileSource);

        bool completed = creationTask.Wait (10000);
        Assert.IsTrue (completed);

        var torrent = creationTask.Result;
        Assert.IsNotNull (torrent);
    }
}

I spent some time debugging, but I don’t know enough about how empty files are supposed to be hashed to provide a fix. If there’s more I can do to help diagnose, please let me know. Thanks for your help!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
borigascommented, Oct 31, 2022

Thanks for the fix! Things are looking good!

Are there plans for an updated beta nuget package? If not, I can build my own, but hoping maybe it’s as simple as 1 CI click for you. Thanks again!

0reactions
borigascommented, Oct 27, 2022

Thanks for the idea. I’m happy to submit a PR with integration tests if you’re willing to make them pass. I’m not familiar enough with the details of the library to be likely to fix something without introducing new bugs. It looks like most of the existing tests are more focused unit tests, so I’ll create a new project unless you have a better idea where to put them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

azureus infinite loop stuck at 99.9% download
I've seen this with more than one client, usually the download will progress as usual but then at the very end it will...
Read more >
Flushing to disk continues indefinitely - Troubleshooting
One solution is to allow the multi-file torrent to start downloading all the files, then go to the "Files" tab and mark the...
Read more >
After download, folder is empty : r/torrents
Using Qbit, and after downloading a particular torrent the folder is always empty despite being able to see the amount downloaded and the ......
Read more >
qBittorrent GUI "not responding" frequently · Issue #15822
When I launch the Torrent Download window from a magnet link or a torrent metadata file. Occasionally, when statistical values are updated.
Read more >
FilePointer gets stuck in infinite loop
The reason it loops forever is the first one: you are reading from the file but not checking if that works. If your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found