THRIFT-657. java: Detect negative length in TBinaryProtocol

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920658 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
index 83c85e1..16c7567 100644
--- a/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java
@@ -365,6 +365,9 @@
   }
 
   protected void checkReadLength(int length) throws TException {
+    if (length < 0) {
+      throw new TException("Negative length: " + length);
+    }
     if (checkReadLength_) {
       readLength_ -= length;
       if (readLength_ < 0) {