You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/01/13 12:26:02 UTC
[3/3] thrift git commit: THRIFT-3542 Add length limit support to Java
test server
THRIFT-3542 Add length limit support to Java test server
This closes #788
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/fc07084a
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/fc07084a
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/fc07084a
Branch: refs/heads/master
Commit: fc07084ada3d788f31beb22ffc6eac73415b843d
Parents: 7b545b5
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Mon Jan 11 14:18:06 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Wed Jan 13 20:25:26 2016 +0900
----------------------------------------------------------------------
.../apache/thrift/protocol/TBinaryProtocol.java | 17 +++++++++--------
.../test/org/apache/thrift/test/TestServer.java | 12 ++++++++++--
test/features/known_failures_Linux.json | 4 ----
3 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/fc07084a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
----------------------------------------------------------------------
diff --git a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
index 4e93606..d7f8b83 100644
--- a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/thrift/blob/fc07084a/lib/java/test/org/apache/thrift/test/TestServer.java
----------------------------------------------------------------------
diff --git a/lib/java/test/org/apache/thrift/test/TestServer.java b/lib/java/test/org/apache/thrift/test/TestServer.java
index ee0866e..14cd2ab 100644
--- a/lib/java/test/org/apache/thrift/test/TestServer.java
+++ b/lib/java/test/org/apache/thrift/test/TestServer.java
@@ -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;
http://git-wip-us.apache.org/repos/asf/thrift/blob/fc07084a/test/features/known_failures_Linux.json
----------------------------------------------------------------------
diff --git a/test/features/known_failures_Linux.json b/test/features/known_failures_Linux.json
index 7a51083..9bf600d 100644
--- a/test/features/known_failures_Linux.json
+++ b/test/features/known_failures_Linux.json
@@ -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",