You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ar...@apache.org on 2019/04/08 10:40:58 UTC

[drill] 05/06: DRILL-7045 UDF string_binary java.lang.IndexOutOfBoundsException

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

arina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit a1986a3fec1634812712e47be0be2565b303ea2d
Author: Jean-Claude <jc...@gmail.com>
AuthorDate: Wed Feb 20 23:52:16 2019 -0500

    DRILL-7045 UDF string_binary java.lang.IndexOutOfBoundsException
    
    UDF string_binary was not reallocating the drillbuffer so it would fill
    up and throw and out of bounds exception
---
 .../apache/drill/exec/expr/fn/impl/StringFunctions.java  |  6 +++---
 .../drill/exec/vector/complex/writer/TestJsonNanInf.java | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
index 6353e55..70db585 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java
@@ -1662,12 +1662,12 @@ public class StringFunctions{
     @Override
     public void eval() {
       byte[] buf = org.apache.drill.common.util.DrillStringUtils.toBinaryString(in.buffer, in.start, in.end).getBytes(charset);
-      buffer.setBytes(0, buf);
-      buffer.setIndex(0, buf.length);
+      out.buffer = buffer.reallocIfNeeded(buf.length);
+      out.buffer.setBytes(0, buf);
+      out.buffer.setIndex(0, buf.length);
 
       out.start = 0;
       out.end = buf.length;
-      out.buffer = buffer;
     }
   }
 
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonNanInf.java b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonNanInf.java
index 138d9b2..851ce0e 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonNanInf.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonNanInf.java
@@ -237,6 +237,22 @@ public class TestJsonNanInf extends BaseTestQuery {
 
 
   @Test
+  public void testLargeStringBinary() throws Exception {
+    String chunk = "0123456789";
+    StringBuilder builder = new StringBuilder();
+    for (int i = 0; i < 1000; i++) {
+      builder.append(chunk);
+    }
+    String data = builder.toString();
+    String query = String.format("select string_binary(binary_string('%s')) from (values(1))", data);
+    List<QueryDataBatch> results = testSqlWithResults(query);
+    RecordBatchLoader batchLoader = new RecordBatchLoader(getAllocator());
+    QueryDataBatch batch = results.get(0);
+    batch.release();
+    batchLoader.clear();
+ }
+
+  @Test
   public void testConvertToJsonFunction() throws Exception {
     String table = "nan_test.csv";
     File file = new File(dirTestWatcher.getRootDir(), table);