mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
THRIFT-3542 Add length limit support to Java test server
This closes #788
This commit is contained in:
parent
7b545b5720
commit
fc07084ada
@ -71,6 +71,10 @@ public class TBinaryProtocol extends TProtocol {
|
||||
this(strictRead, strictWrite, NO_LENGTH_LIMIT, NO_LENGTH_LIMIT);
|
||||
}
|
||||
|
||||
public Factory(long stringLengthLimit, long containerLengthLimit) {
|
||||
this(false, true, stringLengthLimit, containerLengthLimit);
|
||||
}
|
||||
|
||||
public Factory(boolean strictRead, boolean strictWrite, long stringLengthLimit, long containerLengthLimit) {
|
||||
stringLengthLimit_ = stringLengthLimit;
|
||||
containerLengthLimit_ = containerLengthLimit;
|
||||
@ -94,6 +98,10 @@ public class TBinaryProtocol extends TProtocol {
|
||||
this(trans, NO_LENGTH_LIMIT, NO_LENGTH_LIMIT, strictRead, strictWrite);
|
||||
}
|
||||
|
||||
public TBinaryProtocol(TTransport trans, long stringLengthLimit, long containerLengthLimit) {
|
||||
this(trans, stringLengthLimit, containerLengthLimit, false, true);
|
||||
}
|
||||
|
||||
public TBinaryProtocol(TTransport trans, long stringLengthLimit, long containerLengthLimit, boolean strictRead, boolean strictWrite) {
|
||||
super(trans);
|
||||
stringLengthLimit_ = stringLengthLimit;
|
||||
@ -350,10 +358,6 @@ public class TBinaryProtocol extends TProtocol {
|
||||
int size = readI32();
|
||||
|
||||
checkStringReadLength(size);
|
||||
if (stringLengthLimit_ > 0 && size > stringLengthLimit_) {
|
||||
throw new TProtocolException(TProtocolException.SIZE_LIMIT,
|
||||
"String field exceeded string size limit");
|
||||
}
|
||||
|
||||
if (trans_.getBytesRemainingInBuffer() >= size) {
|
||||
try {
|
||||
@ -381,10 +385,7 @@ public class TBinaryProtocol extends TProtocol {
|
||||
public ByteBuffer readBinary() throws TException {
|
||||
int size = readI32();
|
||||
|
||||
if (stringLengthLimit_ > 0 && size > stringLengthLimit_) {
|
||||
throw new TProtocolException(TProtocolException.SIZE_LIMIT,
|
||||
"Binary field exceeded string size limit");
|
||||
}
|
||||
checkStringReadLength(size);
|
||||
|
||||
if (trans_.getBytesRemainingInBuffer() >= size) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(trans_.getBuffer(), trans_.getBufferPosition(), size);
|
||||
|
@ -111,6 +111,8 @@ public class TestServer {
|
||||
String protocol_type = "binary";
|
||||
String server_type = "thread-pool";
|
||||
String domain_socket = "";
|
||||
int string_limit = -1;
|
||||
int container_limit = -1;
|
||||
try {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].startsWith("--port")) {
|
||||
@ -128,6 +130,10 @@ public class TestServer {
|
||||
transport_type.trim();
|
||||
} else if (args[i].equals("--ssl")) {
|
||||
ssl = true;
|
||||
} else if (args[i].startsWith("--string-limit")) {
|
||||
string_limit = Integer.valueOf(args[i].split("=")[1]);
|
||||
} else if (args[i].startsWith("--container-limit")) {
|
||||
container_limit = Integer.valueOf(args[i].split("=")[1]);
|
||||
} else if (args[i].equals("--help")) {
|
||||
System.out.println("Allowed options:");
|
||||
System.out.println(" --help\t\t\tProduce help message");
|
||||
@ -136,6 +142,8 @@ public class TestServer {
|
||||
System.out.println(" --protocol=arg (=" + protocol_type + ")\tProtocol: binary, json, compact");
|
||||
System.out.println(" --ssl\t\t\tEncrypted Transport using SSL");
|
||||
System.out.println(" --server-type=arg (=" + server_type +")\n\t\t\t\tType of server: simple, thread-pool, nonblocking, threaded-selector");
|
||||
System.out.println(" --string-limit=arg (=" + string_limit + ")\tString read length limit");
|
||||
System.out.println(" --container-limit=arg (=" + container_limit + ")\tContainer read length limit");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@ -186,9 +194,9 @@ public class TestServer {
|
||||
if (protocol_type.equals("json")) {
|
||||
tProtocolFactory = new TJSONProtocol.Factory();
|
||||
} else if (protocol_type.equals("compact")) {
|
||||
tProtocolFactory = new TCompactProtocol.Factory();
|
||||
tProtocolFactory = new TCompactProtocol.Factory(string_limit, container_limit);
|
||||
} else {
|
||||
tProtocolFactory = new TBinaryProtocol.Factory();
|
||||
tProtocolFactory = new TBinaryProtocol.Factory(string_limit, container_limit);
|
||||
}
|
||||
|
||||
TTransportFactory tTransportFactory = null;
|
||||
|
@ -17,10 +17,6 @@
|
||||
"hs-limit_container_length_compact_buffered-ip",
|
||||
"hs-limit_string_length_binary_buffered-ip",
|
||||
"hs-limit_string_length_compact_buffered-ip",
|
||||
"java-limit_container_length_binary_buffered-ip",
|
||||
"java-limit_container_length_compact_buffered-ip",
|
||||
"java-limit_string_length_binary_buffered-ip",
|
||||
"java-limit_string_length_compact_buffered-ip",
|
||||
"nodejs-limit_container_length_binary_buffered-ip",
|
||||
"nodejs-limit_container_length_compact_buffered-ip",
|
||||
"nodejs-limit_string_length_binary_buffered-ip",
|
||||
|
Loading…
Reference in New Issue
Block a user