You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2021/06/10 23:01:14 UTC

[thrift] 02/03: THRIFT-5383 TJSONProtocol Java readString throws on bounds check Client: java Patch: Aaron St. George

This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch 0.14.2
in repository https://gitbox.apache.org/repos/asf/thrift.git

commit d604602064e9218cc1f0153a4f83dff22fa1b44e
Author: aaronstgeorge-wf <aa...@workiva.com>
AuthorDate: Tue Mar 30 00:35:13 2021 +0200

    THRIFT-5383 TJSONProtocol Java readString throws on bounds check
    Client: java
    Patch: Aaron St. George
    
    This closes #2366
---
 lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java |  4 +---
 .../test/org/apache/thrift/protocol/TestTJSONProtocol.java | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java b/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java
index 6bb49cb..95eb62c 100644
--- a/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java
+++ b/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java
@@ -972,9 +972,7 @@ public class TJSONProtocol extends TProtocol {
 
   @Override
   public String readString() throws TException {
-    String str = readJSONString(false).toString(StandardCharsets.UTF_8);
-    getTransport().checkReadBytesAvailable(str.length() * getMinSerializedSize(TType.STRING));
-    return str;
+    return readJSONString(false).toString(StandardCharsets.UTF_8);
   }
 
   @Override
diff --git a/lib/java/test/org/apache/thrift/protocol/TestTJSONProtocol.java b/lib/java/test/org/apache/thrift/protocol/TestTJSONProtocol.java
index c2ca1fa..ecbd101 100644
--- a/lib/java/test/org/apache/thrift/protocol/TestTJSONProtocol.java
+++ b/lib/java/test/org/apache/thrift/protocol/TestTJSONProtocol.java
@@ -45,4 +45,18 @@ public class TestTJSONProtocol extends ProtocolTestBase {
 
     assertEquals(expectedString, protocol.readString());
   }
+
+  public void testExactlySizedBuffer() throws TException {
+    // Regression test for https://issues.apache.org/jira/browse/THRIFT-5383.
+    // Ensures that a JSON string can be read after writing to a buffer just
+    // large enough to contain it.
+    String inputString = "abcdefg";
+    TMemoryBuffer buffer = new TMemoryBuffer(inputString.length() + 2);
+
+    TJSONProtocol protocol = new TJSONProtocol(buffer);
+    protocol.writeString(inputString);
+    String outputString = protocol.readString();
+
+    assertEquals(inputString, outputString);
+  }
 }