jash-kothari-forks / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
0 stars 0 forks source link

create invalid torrent file from magnet links #483

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. add a magnet link to session
2. handle metadata_received_alert
3. carete and save torrent while handeling metadata_received_alert

What is the expected output? What do you see instead?
torrent was created but it couldn't be added. I recived a error "expected 
string in bebcoded string"

What version of the product are you using? On what operating system?
last valiable 16.10. OS windows.

Please provide any additional information below.
i fixed this by changing the way of saving generated torrent data.
In documentation recomended to use following code:
[code]
torrent_handle h = alert->handle();
if (h.is_valid()) {
        torrent_info const& ti = h.get_torrent_info();
        create_torrent ct(ti);
        entry te = ct.generate();
        std::vector<char> buffer;
        bencode(std::back_inserter(buffer), te);
        FILE* f = fopen((to_hex(ti.info_hash().to_string()) + ".torrent").c_str(), "w+");
        if (f) {
                fwrite(&buffer[0], 1, buffer.size(), f);
                fclose(f);
        }
}
[code]
if we use it error occures.
if i use this code 
[code]
torrent_handle h = alert->handle();
if (h.is_valid()) {
        torrent_info const& ti = h.get_torrent_info();
        create_torrent ct(ti);
        std::ofstream out(complete(combine_path("CT_DATA",to_hex(ti.info_hash().to_string()) + ".torrent")).c_str(), std::ios_base::binary);
    bencode(std::ostream_iterator<char>(out), ct.generate());
}
[code]
torrent will be valid

Original issue reported on code.google.com by ruslan.f...@gmail.com on 24 May 2013 at 8:28

GoogleCodeExporter commented 8 years ago
I think this bug was relaited to x64 wondows OS and caused by data packing.

Original comment by ruslan.f...@gmail.com on 24 May 2013 at 8:40

GoogleCodeExporter commented 8 years ago
it sounds like the recommendation in the documentation should say "wb+" in the 
fopen call. that would be enough, right?

Original comment by arvid.no...@gmail.com on 25 May 2013 at 6:37

GoogleCodeExporter commented 8 years ago
oh yes you are right... I dont pay attention on fopen parametrs...

Original comment by ruslan.f...@gmail.com on 25 May 2013 at 7:58

GoogleCodeExporter commented 8 years ago

Original comment by arvid.no...@gmail.com on 26 May 2013 at 2:43