forked from I2P_Developers/i2p.i2p
* i2psnark:
- Escape control chars in encodePath() - Increase max piece size to 8 MB (ticket #1347)
This commit is contained in:
@@ -74,7 +74,7 @@ public class Storage
|
|||||||
/** The default piece size. */
|
/** The default piece size. */
|
||||||
private static final int DEFAULT_PIECE_SIZE = 256*1024;
|
private static final int DEFAULT_PIECE_SIZE = 256*1024;
|
||||||
/** bigger than this will be rejected */
|
/** bigger than this will be rejected */
|
||||||
public static final int MAX_PIECE_SIZE = 4*1024*1024;
|
public static final int MAX_PIECE_SIZE = 8*1024*1024;
|
||||||
/** The maximum number of pieces in a torrent. */
|
/** The maximum number of pieces in a torrent. */
|
||||||
public static final int MAX_PIECES = 10*1024;
|
public static final int MAX_PIECES = 10*1024;
|
||||||
public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES;
|
public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES;
|
||||||
|
@@ -56,6 +56,10 @@ class URIUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Encode a URI path.
|
/** Encode a URI path.
|
||||||
|
*
|
||||||
|
* Somewhat oddly, this encodes all chars >= 0x80 if buf is null, (strict RFC 2396)
|
||||||
|
* but only the control, space, and special chars if buf is non-null.
|
||||||
|
*
|
||||||
* @param path The path the encode
|
* @param path The path the encode
|
||||||
* @param buf StringBuilder to encode path into (or null)
|
* @param buf StringBuilder to encode path into (or null)
|
||||||
* @return The StringBuilder or null if no substitutions required.
|
* @return The StringBuilder or null if no substitutions required.
|
||||||
@@ -83,7 +87,7 @@ class URIUtil
|
|||||||
buf=new StringBuilder(path.length()*2);
|
buf=new StringBuilder(path.length()*2);
|
||||||
break loop;
|
break loop;
|
||||||
default:
|
default:
|
||||||
if (c>127)
|
if (c >= 0x7f || c <= 0x1f)
|
||||||
{
|
{
|
||||||
bytes = DataHelper.getUTF8(path);
|
bytes = DataHelper.getUTF8(path);
|
||||||
buf=new StringBuilder(path.length()*2);
|
buf=new StringBuilder(path.length()*2);
|
||||||
@@ -132,12 +136,12 @@ class URIUtil
|
|||||||
case ' ':
|
case ' ':
|
||||||
buf.append("%20");
|
buf.append("%20");
|
||||||
continue;
|
continue;
|
||||||
|
case 0x7f:
|
||||||
|
buf.append("%7F");
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
if (c<0)
|
if (c <= 0x1f) // includes negative
|
||||||
{
|
|
||||||
buf.append('%');
|
|
||||||
toHex(c,buf);
|
toHex(c,buf);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
buf.append((char)c);
|
buf.append((char)c);
|
||||||
continue;
|
continue;
|
||||||
@@ -180,7 +184,10 @@ class URIUtil
|
|||||||
buf.append("%20");
|
buf.append("%20");
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
buf.append(c);
|
if (c <= 0x1f || (c >= 0x7f && c <= 0x9f) || Character.isSpaceChar(c))
|
||||||
|
toHex(c,buf);
|
||||||
|
else
|
||||||
|
buf.append(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,11 +202,27 @@ class URIUtil
|
|||||||
*/
|
*/
|
||||||
private static void toHex(byte b, StringBuilder buf)
|
private static void toHex(byte b, StringBuilder buf)
|
||||||
{
|
{
|
||||||
|
buf.append('%');
|
||||||
int d=0xf&((0xF0&b)>>4);
|
int d=0xf&((0xF0&b)>>4);
|
||||||
buf.append((char)((d>9?('A'-10):'0')+d));
|
buf.append((char)((d>9?('A'-10):'0')+d));
|
||||||
d=0xf&b;
|
d=0xf&b;
|
||||||
buf.append((char)((d>9?('A'-10):'0')+d));
|
buf.append((char)((d>9?('A'-10):'0')+d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UTF-8
|
||||||
|
*/
|
||||||
|
private static void toHex(char c, StringBuilder buf)
|
||||||
|
{
|
||||||
|
if (c > 0x7f) {
|
||||||
|
byte[] b = DataHelper.getUTF8(Character.toString(c));
|
||||||
|
for (int i = 0; i < b.length; i++) {
|
||||||
|
toHex(b[i], buf);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toHex((byte) c, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user