diff options
author | aaronstgeorge-wf <aaron.stgeorge@workiva.com> | 2021-03-30 00:35:13 +0200 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2021-06-11 00:38:44 +0200 |
commit | d604602064e9218cc1f0153a4f83dff22fa1b44e (patch) | |
tree | 73d74944569d5b04e7e3611f4d41f334553a334b | |
parent | c1e33a8436d716c49501417a5c8755ffd56c8719 (diff) | |
download | thrift-d604602064e9218cc1f0153a4f83dff22fa1b44e.tar.gz |
THRIFT-5383 TJSONProtocol Java readString throws on bounds check
Client: java
Patch: Aaron St. George
This closes #2366
-rw-r--r-- | lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java | 4 | ||||
-rw-r--r-- | lib/java/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 6bb49cb2f..95eb62ced 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 c2ca1fa7a..ecbd10188 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); + } } |