-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
(Update) use array_is_list
when bencode
#3297
Conversation
array_is_list
when bencodearray_is_list
when bencode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked all locations bencode
is called and there were no cases where an explicit list was passed in. Implicitly, the only variables that were passed in were those decoded using the bdecode
function, which after checking, there are no cases where lists might have integer keys that are out of order. So I think we're safe to assume a list is only a list when the keys are in order compared to the previous implementation where only the type was checked.
Thanks!
Yes, I agree with you. the One more thing, Is UNIT3D team willing to use my library https://github.com/Rhilip/Bencode for Bencode and Torrent ? If this lirary meets your requirements, I'd be more than willing to make a pull request. |
After this PR, I actually started doing a big refactor of the bencode helper and adding a bunch of tests. I was going based off the tests in https://github.com/arvidn/libtorrent/blob/RC_2_0/test/test_bdecode.cpp as a baseline. Does your library have an equivalent for each test in there? I think it might be missing a few such as defining a recursion limit which could prove useful. |
the Rhilip/Bencode library has used for NexusPHP and other tracker, I already add some tests in my library. |
If you're willing to add those tests, definitely take a stab at it! This code in UNIT3D hasn't been updated for years and definitely need some major improvement with edge case handling. Although one thing to worry about is since we save uploaded .torrents, we've saved previous torrents with less strict handling, and when we go to parse these torrents again we may run into issues that I haven't fully thought through yet. In UNIT3D, we would probably need to wrap the library so that we can handle all the exception cases in a single spot and decide which errors should be allowed in decoding previously saved torrents, but prevent any new uploads of out-of-spec torrent files. |
If you're looking into replacing your decoder, I'll suggest using my library at https://github.com/s9e/Bencode if that's something that you can work into your project. It's only a decoder/encoder, it's not meant to manipulate files. It uses |
I don't think the For test, I total review https://github.com/arvidn/libtorrent/blob/RC_2_0/test/test_bdecode.cpp?rgh-link-date=2023-12-18T07%3A09%3A09Z , 4 tests and 10 assertions add in commit Rhilip/Bencode@6ff306f . And I think it's enough. Some tests in arvidn/libtorrent may overdesign in PHP language since it build for btclient and torrent maker, for example, https://github.com/arvidn/libtorrent/blob/9c1897645265c6a450930e766ab46c02a240891f/test/test_bdecode.cpp#L482-L512 .Or just converage by other exception, mostly by |
I mentioned |
PHP 8.1
add a new functionarray_is_list
and since UNIT3d 7.x.x min Required PHP Version is 8.2.We can safely simple the list or dict Checks by this new
array_is_list
function.And I completely delete the
isset($d['isDct'])
check, since no 'isDct' key is created in the bdecode step and whole project.