Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIVE-26713: StringExpr ArrayIndexOutOfBoundsException with LIKE '%xxx%' #4999

Merged
merged 9 commits into from
Jan 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,15 @@ public int find(byte[] input, int start, int len) {
}
s_tmp--;
}
next += shift[input[next] & MAX_BYTE];

// if the character string contains control characters,
// overflow occurs.
int shiftIndex = input[next] & MAX_BYTE;
if (shiftIndex >= MAX_BYTE) {
next++;
} else {
next += shift[shiftIndex];
}
}
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.*;
zhangbutao marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -49,6 +50,24 @@ public void test() throws Exception {
assertEquals("Testing match at end of string", 24, find(pattern, input4));
}

@Test
public void test2() throws Exception {
ryukobayashi marked this conversation as resolved.
Show resolved Hide resolved
StringExpr.Finder pattern = compile("pattern");
assertNotNull(pattern);

byte b = -1;
byte[] controlBytes1 = "abcedf".getBytes(StandardCharsets.UTF_8);
byte[] controlBytes2 = "pattern".getBytes(StandardCharsets.UTF_8);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(controlBytes1);
outputStream.write(b);
outputStream.write(controlBytes2);
byte[] controlChar = outputStream.toByteArray();
outputStream.close();

assertEquals("Testing valid match", 7, pattern.find(controlChar, 0, controlChar.length));
}

private StringExpr.Finder compile(String pattern) {
return StringExpr.compile(pattern.getBytes(StandardCharsets.UTF_8));
}
Expand Down