Skip to content

Commit 08f0b86

Browse files
committed
Merge #267: New binary to parse torrent files (only for debugging purposes)
d9cdd65 feat: new binary to par torrent files (Jose Celano) Pull request description: I'm trying to fix bug #266 When I try to upload this torrent: https://academictorrents.com/details/3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462 I get this error trying to parse it: ``` InvalidType("Invalid Type: sequence (expected: `field identifier`)") ``` I've tried to reproduce the error with a clean project: https://github.com/torrust/torrust-parse-torrent But It works. I've added a binary to reproduce the error in this project. You can run it with: ``` cargo run --bin parse_torrent ./tests/fixtures/torrents/MC_GRID.zip-3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462.torrent ``` Output: ```s Reading the torrent file ... Decoding torrent with standard serde implementation ... InvalidType("Invalid Type: sequence (expected: `field identifier`)") Error: Custom { kind: Other, error: "Error: invalid torrent!. Invalid Type: sequence (expected: `field identifier`)" } ``` I need more ideas about how to solve this bug. I've checked the dependencies, and It does not work even if I use the same "serde" dependencies in this project. The torrent only has two different things: - The "pieces" field is big. - It has an extra field from BEP 19. I only have two more things to test: - ~~Create another torrent with a big "pieces" field. Only to check if the size is the problem~~. DONE. - Clone the "serve" crate and try to debug the code. I think the error is thrown [here](https://github.com/serde-rs/serde/blob/dad15b9fd0bef97b7a7c90a8a165b6ffbc682cae/serde/src/de/mod.rs#L1646). It seems the deserializer is expecting a file identifier (I guess for a Dictionary) and is getting a sequence. Top commit has no ACKs. Tree-SHA512: c9f02021801d492e34b7550662cfb6747bbf81f3724c3afdd3d92e22061066c400b721f35e80100d3253ff79fbda10d0bf0f7ea29df964f57ee97a1607b50fd3
2 parents 9ba65cc + d9cdd65 commit 08f0b86

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

.vscode/launch.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug executable 'parse_torrent'",
6+
"type": "cppdbg",
7+
"request": "launch",
8+
"program": "${workspaceFolder}/target/debug/parse_torrent",
9+
"args": ["./tests/fixtures/torrents/MC_GRID.zip-3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462.torrent"],
10+
"stopAtEntry": false,
11+
"cwd": "${workspaceFolder}",
12+
"environment": [],
13+
"externalConsole": false,
14+
"MIMode": "gdb",
15+
"setupCommands": [
16+
{
17+
"description": "Enable pretty-printing for gdb",
18+
"text": "-enable-pretty-printing",
19+
"ignoreFailures": true
20+
}
21+
],
22+
"preLaunchTask": "cargo build",
23+
"miDebuggerPath": "/usr/bin/gdb",
24+
"linux": {
25+
"miDebuggerPath": "/usr/bin/gdb"
26+
},
27+
"windows": {
28+
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe"
29+
},
30+
"osx": {
31+
"miDebuggerPath": "/usr/local/bin/gdb"
32+
}
33+
}
34+
]
35+
}

src/bin/parse_torrent.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! Command line tool to parse a torrent file and print the decoded torrent.
2+
//!
3+
//! It's only used for debugging purposes.
4+
use std::env;
5+
use std::fs::File;
6+
use std::io::{self, Read};
7+
8+
use serde_bencode::de::from_bytes;
9+
use serde_bencode::value::Value as BValue;
10+
use torrust_index_backend::utils::parse_torrent;
11+
12+
fn main() -> io::Result<()> {
13+
let args: Vec<String> = env::args().collect();
14+
if args.len() != 2 {
15+
eprintln!("Usage: cargo run --bin parse_torrent <PATH_TO_TORRENT_FILE>");
16+
eprintln!("Example: cargo run --bin parse_torrent ./tests/fixtures/torrents/MC_GRID.zip-3cd18ff2d3eec881207dcc5ca5a2c3a2a3afe462.torrent");
17+
std::process::exit(1);
18+
}
19+
20+
println!("Reading the torrent file ...");
21+
22+
let mut file = File::open(&args[1])?;
23+
let mut bytes = Vec::new();
24+
file.read_to_end(&mut bytes)?;
25+
26+
println!("Decoding torrent with standard serde implementation ...");
27+
28+
match from_bytes::<BValue>(&bytes) {
29+
Ok(_value) => match parse_torrent::decode_torrent(&bytes) {
30+
Ok(torrent) => {
31+
println!("Parsed torrent: \n{torrent:#?}");
32+
Ok(())
33+
}
34+
Err(e) => Err(io::Error::new(io::ErrorKind::Other, format!("Error: invalid torrent!. {e}"))),
35+
},
36+
Err(e) => Err(io::Error::new(
37+
io::ErrorKind::Other,
38+
format!("Error: invalid bencode data!. {e}"),
39+
)),
40+
}
41+
}
Binary file not shown.

0 commit comments

Comments
 (0)