HADOOP-18471. Fixed ArrayIndexOutOfBoundsException in DefaultStringifier (#4957)

Contributed by FuzzingTeam
This commit is contained in:
FuzzingTeam 2022-10-20 22:42:17 +05:30 committed by GitHub
parent a996d889ec
commit 7f69e09290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -158,6 +158,9 @@ public class DefaultStringifier<T> implements Stringifier<T> {
public static <K> void storeArray(Configuration conf, K[] items,
String keyName) throws IOException {
if (items.length == 0) {
throw new IndexOutOfBoundsException();
}
DefaultStringifier<K> stringifier = new DefaultStringifier<K>(conf,
GenericsUtil.getClass(items[0]));
try {

View File

@ -26,6 +26,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
import static org.junit.Assert.assertEquals;
public class TestDefaultStringifier {
@ -98,7 +99,7 @@ public class TestDefaultStringifier {
}
@Test
public void testStoreLoadArray() throws IOException {
public void testStoreLoadArray() throws Exception {
LOG.info("Testing DefaultStringifier#storeArray() and #loadArray()");
conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization");
@ -107,6 +108,8 @@ public class TestDefaultStringifier {
Integer[] array = new Integer[] {1,2,3,4,5};
intercept(IndexOutOfBoundsException.class, () ->
DefaultStringifier.storeArray(conf, new Integer[] {}, keyName));
DefaultStringifier.storeArray(conf, array, keyName);
Integer[] claimedArray = DefaultStringifier.<Integer>loadArray(conf, keyName, Integer.class);