* i2psnark:

- Escape control chars in encodePath()
   - Increase max piece size to 8 MB (ticket #1347)
This commit is contained in:
zzz
2014-08-21 11:49:58 +00:00
parent 33b7f08d5c
commit dee6e16e6c
2 changed files with 30 additions and 7 deletions

View File

@ -74,7 +74,7 @@ public class Storage
/** The default piece size. */
private static final int DEFAULT_PIECE_SIZE = 256*1024;
/** 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. */
public static final int MAX_PIECES = 10*1024;
public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES;

View File

@ -56,6 +56,10 @@ class URIUtil
}
/** 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 buf StringBuilder to encode path into (or null)
* @return The StringBuilder or null if no substitutions required.
@ -83,7 +87,7 @@ class URIUtil
buf=new StringBuilder(path.length()*2);
break loop;
default:
if (c>127)
if (c >= 0x7f || c <= 0x1f)
{
bytes = DataHelper.getUTF8(path);
buf=new StringBuilder(path.length()*2);
@ -132,12 +136,12 @@ class URIUtil
case ' ':
buf.append("%20");
continue;
case 0x7f:
buf.append("%7F");
continue;
default:
if (c<0)
{
buf.append('%');
if (c <= 0x1f) // includes negative
toHex(c,buf);
}
else
buf.append((char)c);
continue;
@ -180,7 +184,10 @@ class URIUtil
buf.append("%20");
continue;
default:
buf.append(c);
if (c <= 0x1f || (c >= 0x7f && c <= 0x9f) || Character.isSpaceChar(c))
toHex(c,buf);
else
buf.append(c);
continue;
}
}
@ -195,11 +202,27 @@ class URIUtil
*/
private static void toHex(byte b, StringBuilder buf)
{
buf.append('%');
int d=0xf&((0xF0&b)>>4);
buf.append((char)((d>9?('A'-10):'0')+d));
d=0xf&b;
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);
}
}
}