mirror of https://github.com/zlatinb/muwire
tighten piece size range
parent
f6ee49c0f5
commit
8801546854
|
@ -13,6 +13,7 @@ import java.security.NoSuchAlgorithmException
|
|||
|
||||
class FileHasher {
|
||||
|
||||
public static final int MIN_PIECE_SIZE_POW2 = 17
|
||||
public static final int MAX_PIECE_SIZE_POW2 = 37
|
||||
/** max size of shared file is 128 GB */
|
||||
public static final long MAX_SIZE = 0x1L << MAX_PIECE_SIZE_POW2
|
||||
|
@ -25,7 +26,7 @@ class FileHasher {
|
|||
*/
|
||||
static int getPieceSize(long size) {
|
||||
if (size <= 0x1 << 30)
|
||||
return 17
|
||||
return MIN_PIECE_SIZE_POW2
|
||||
|
||||
for (int i = 31; i <= MAX_PIECE_SIZE_POW2; i++) {
|
||||
if (size <= 0x1L << i) {
|
||||
|
|
|
@ -35,7 +35,7 @@ class ResultsParser {
|
|||
throw new InvalidSearchResultException("length missing or invalid, $json.size")
|
||||
if (json.infohash == null)
|
||||
throw new InvalidSearchResultException("infohash missing")
|
||||
if (json.pieceSize == null || json.pieceSize <= 0 || json.pieceSize > FileHasher.MAX_PIECE_SIZE_POW2)
|
||||
if (json.pieceSize == null || json.pieceSize < FileHasher.MIN_PIECE_SIZE_POW2 || json.pieceSize > FileHasher.MAX_PIECE_SIZE_POW2)
|
||||
throw new InvalidSearchResultException("pieceSize missing or invalid, $json.pieceSize")
|
||||
if (!(json.hashList instanceof List))
|
||||
throw new InvalidSearchResultException("hashlist not a list")
|
||||
|
@ -76,7 +76,7 @@ class ResultsParser {
|
|||
throw new InvalidSearchResultException("length missing or invalid $json.size")
|
||||
if (json.infohash == null)
|
||||
throw new InvalidSearchResultException("infohash missing")
|
||||
if (json.pieceSize == null || json.pieceSize <= 0 || json.pieceSize > FileHasher.MAX_PIECE_SIZE_POW2)
|
||||
if (json.pieceSize == null || json.pieceSize < FileHasher.MIN_PIECE_SIZE_POW2 || json.pieceSize > FileHasher.MAX_PIECE_SIZE_POW2)
|
||||
throw new InvalidSearchResultException("pieceSize missing or invalid, $json.pieceSize")
|
||||
if (json.hashList != null)
|
||||
throw new InvalidSearchResultException("V2 result with hashlist")
|
||||
|
|
Loading…
Reference in New Issue