i2psnark: Defensive checks for v2 format files and magnet links

This commit is contained in:
zzz
2020-09-16 14:42:11 +00:00
parent 6ffebbd5c1
commit dca45a9b18
4 changed files with 26 additions and 5 deletions

View File

@@ -238,8 +238,18 @@ public class MetaInfo
piece_length = val.getInt();
val = info.get("pieces");
if (val == null)
if (val == null) {
// BEP 52
// We do the check here because a torrent file could be combined v1/v2,
// so a version 2 value isn't by itself fatal
val = info.get("meta version");
if (val != null) {
int version = val.getInt();
if (version != 1)
throw new InvalidBEncodingException("Version " + version + " torrent file not supported");
}
throw new InvalidBEncodingException("Missing piece bytes");
}
piece_hashes = val.getBytes();
val = info.get("length");