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

[core] Replace invalid characters in the generated path #493

Merged
merged 4 commits into from
Dec 22, 2021

Conversation

alanmcgovern
Copy link
Owner

Replace invalid characters with the hex equivalent (and hope
there is no collision).

Addresses #491

Replace invalid characters with the hex equivalent (and hope
there is no collision).

Addresses #491
@alanmcgovern alanmcgovern linked an issue Dec 21, 2021 that may be closed by this pull request
@Niegen
Copy link

Niegen commented Dec 21, 2021

Hi Alan,

Thanks for the fix.

The torrent downloaded correctly, however, the " were replaced by the string 22.

Not a huge problem by itself, but then I cannot locate the actual final torrent folder by doing

Path.Combine(Options.Instance.OutputDirectory, torrent.Name)

since torrent.Name doesn't reflect the "fixed" folder name and still contains the invalid characters.

Maybe you should add a read only property for the final folder full path?

You are very close though. Thanks again.

@alanmcgovern
Copy link
Owner Author

You can find the full paths to all files by accessing the TorrentManager.Files list and checking the FullPath property.

In the meantime, ill have a think about the best way to expose a "ContainingDirectory" property which represents the sanitized path!

'SavePath' is the path the user provides. By default a multi-file
torrent will create a sub-directory within the directory specified
by 'SavePath', and all files will be stored there.

For single file torrents, the file will be stored directly within
'SavePath'.

Hopefully the docs make this distinction clear and unambiguous.
Firstly, ensure the constructed path doesn't contain
invalid characters.

Secondly, ensure that path traversal attempts based on
'Torrent.Name' are rejected the same way they are for
traversal attempts for individual torrent files.

Any torrent attempting traversal will not be loaded.
@alanmcgovern
Copy link
Owner Author

There's a new TorrentManager.ContainingDirectory property. I added xml docs which explain the difference between this and TorrentManager.SavePath. For a single file torrent ContainingDirectory and SavePath are the same. For a multi-file torrent, when TorrentSettings.CreateContainingDirectory is enabled, the escaped version of Torrent.Name is appended to SavePath and is stored in the ContainingDirectory property.

If you use the public APIs to move files to different locations then these properties will have no clear/accurate meaning. However TorrentFileInfo.FullPath will always be correct. You can get this by looping over all the files in a torrentmanager :)

I'll merge this, and release an updated nuget package, as it seems to solve your first issue, and your followup issue has been solved too!

Do let me know if you have any further issues/questions!

@alanmcgovern alanmcgovern merged commit deed484 into master Dec 22, 2021
@alanmcgovern alanmcgovern deleted the invalid-chars-in-paths branch December 22, 2021 14:43
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

Successfully merging this pull request may close these issues.

Invalid Characters in Path
2 participants