diff --git a/projects/apache-commons-lang/ArrayUtilsFuzzer.java b/projects/apache-commons-lang/ArrayUtilsFuzzer.java new file mode 100644 index 000000000000..532ab787f030 --- /dev/null +++ b/projects/apache-commons-lang/ArrayUtilsFuzzer.java @@ -0,0 +1,375 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.ArrayFill; +import org.apache.commons.lang3.ArraySorter; +import org.apache.commons.lang3.ArrayUtils; + +/** This fuzzer targets the methods of the ArrayUtils class in the base package. */ +public class ArrayUtilsFuzzer { + private static boolean[] boolArray; + private static byte[] byteArray; + private static char[] charArray; + private static double[] doubleArray; + private static float[] floatArray; + private static int[] intArray; + private static long[] longArray; + private static short[] shortArray; + private static String[] strArray; + + public static void fuzzerInitialize() { + boolArray = new boolean[1]; + byteArray = new byte[1]; + charArray = new char[1]; + doubleArray = new double[1]; + floatArray = new float[1]; + intArray = new int[1]; + longArray = new long[1]; + shortArray = new short[1]; + strArray = new String[1]; + } + + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + cleanLargeArray(); + + for (Integer count = 0; count < data.consumeInt(1, 10); count++) { + switch (data.consumeInt(1, 89)) { + case 1: + ArrayUtils.add(boolArray, data.consumeBoolean()); + break; + case 2: + ArrayUtils.add(byteArray, data.consumeByte()); + break; + case 3: + ArrayUtils.add(charArray, data.consumeChar()); + break; + case 4: + ArrayUtils.add(doubleArray, data.consumeDouble()); + break; + case 5: + ArrayUtils.add(floatArray, data.consumeFloat()); + break; + case 6: + ArrayUtils.add(intArray, data.consumeInt()); + break; + case 7: + ArrayUtils.add(longArray, data.consumeLong()); + break; + case 8: + ArrayUtils.add(shortArray, data.consumeShort()); + break; + case 9: + ArrayUtils.add(strArray, data.consumeString(10)); + break; + case 10: + ArrayUtils.addAll(boolArray, data.consumeBoolean()); + break; + case 11: + ArrayUtils.addAll(byteArray, data.consumeByte()); + break; + case 12: + ArrayUtils.addAll(charArray, data.consumeChar()); + break; + case 13: + ArrayUtils.addAll(doubleArray, data.consumeDouble()); + break; + case 14: + ArrayUtils.addAll(floatArray, data.consumeFloat()); + break; + case 15: + ArrayUtils.addAll(intArray, data.consumeInt()); + break; + case 16: + ArrayUtils.addAll(longArray, data.consumeLong()); + break; + case 17: + ArrayUtils.addAll(shortArray, data.consumeShort()); + break; + case 18: + ArrayUtils.addAll(strArray, data.consumeString(10)); + break; + case 19: + ArrayUtils.addFirst(boolArray, data.consumeBoolean()); + break; + case 20: + ArrayUtils.addFirst(byteArray, data.consumeByte()); + break; + case 21: + ArrayUtils.addFirst(charArray, data.consumeChar()); + break; + case 22: + ArrayUtils.addFirst(doubleArray, data.consumeDouble()); + break; + case 23: + ArrayUtils.addFirst(floatArray, data.consumeFloat()); + break; + case 24: + ArrayUtils.addFirst(intArray, data.consumeInt()); + break; + case 25: + ArrayUtils.addFirst(longArray, data.consumeLong()); + break; + case 26: + ArrayUtils.addFirst(shortArray, data.consumeShort()); + break; + case 27: + ArrayUtils.addFirst(strArray, data.consumeString(10)); + break; + case 28: + ArrayUtils.reverse(boolArray); + break; + case 29: + ArrayUtils.reverse(byteArray); + break; + case 30: + ArrayUtils.reverse(charArray); + break; + case 31: + ArrayUtils.reverse(doubleArray); + break; + case 32: + ArrayUtils.reverse(floatArray); + break; + case 33: + ArrayUtils.reverse(intArray); + break; + case 34: + ArrayUtils.reverse(longArray); + break; + case 35: + ArrayUtils.reverse(shortArray); + break; + case 36: + ArrayUtils.reverse(strArray); + break; + case 37: + ArrayUtils.shift(boolArray, 10); + break; + case 38: + ArrayUtils.shift(byteArray, 10); + break; + case 39: + ArrayUtils.shift(charArray, 10); + break; + case 40: + ArrayUtils.shift(doubleArray, 10); + break; + case 41: + ArrayUtils.shift(floatArray, 10); + break; + case 42: + ArrayUtils.shift(intArray, 10); + break; + case 43: + ArrayUtils.shift(longArray, 10); + break; + case 44: + ArrayUtils.shift(shortArray, 10); + break; + case 45: + ArrayUtils.shift(strArray, 10); + break; + case 46: + ArrayUtils.shuffle(boolArray); + break; + case 47: + ArrayUtils.shuffle(byteArray); + break; + case 48: + ArrayUtils.shuffle(charArray); + break; + case 49: + ArrayUtils.shuffle(doubleArray); + break; + case 50: + ArrayUtils.shuffle(floatArray); + break; + case 51: + ArrayUtils.shuffle(intArray); + break; + case 52: + ArrayUtils.shuffle(longArray); + break; + case 53: + ArrayUtils.shuffle(shortArray); + break; + case 54: + ArrayUtils.shuffle(strArray); + break; + case 55: + ArrayUtils.swap(boolArray, 0, 1); + break; + case 56: + ArrayUtils.swap(byteArray, 0, 1); + break; + case 57: + ArrayUtils.swap(charArray, 0, 1); + break; + case 58: + ArrayUtils.swap(doubleArray, 0, 1); + break; + case 59: + ArrayUtils.swap(floatArray, 0, 1); + break; + case 60: + ArrayUtils.swap(intArray, 0, 1); + break; + case 61: + ArrayUtils.swap(longArray, 0, 1); + break; + case 62: + ArrayUtils.swap(shortArray, 0, 1); + break; + case 63: + ArrayUtils.swap(strArray, 0, 1); + break; + case 64: + ArrayUtils.toPrimitive(ArrayUtils.toObject(boolArray)); + break; + case 65: + ArrayUtils.toPrimitive(ArrayUtils.toObject(byteArray)); + break; + case 66: + ArrayUtils.toPrimitive(ArrayUtils.toObject(charArray)); + break; + case 67: + ArrayUtils.toPrimitive(ArrayUtils.toObject(doubleArray)); + break; + case 68: + ArrayUtils.toPrimitive(ArrayUtils.toObject(floatArray)); + break; + case 69: + ArrayUtils.toPrimitive(ArrayUtils.toObject(intArray)); + break; + case 70: + ArrayUtils.toPrimitive(ArrayUtils.toObject(longArray)); + break; + case 71: + ArrayUtils.toPrimitive(ArrayUtils.toObject(shortArray)); + break; + case 72: + ArrayUtils.removeElement(boolArray, data.consumeBoolean()); + break; + case 73: + ArrayUtils.removeElement(byteArray, data.consumeByte()); + break; + case 74: + ArrayUtils.removeElement(charArray, data.consumeChar()); + break; + case 75: + ArrayUtils.removeElement(doubleArray, data.consumeDouble()); + break; + case 76: + ArrayUtils.removeElement(floatArray, data.consumeFloat()); + break; + case 77: + ArrayUtils.removeElement(intArray, data.consumeInt()); + break; + case 78: + ArrayUtils.removeElement(longArray, data.consumeLong()); + break; + case 79: + ArrayUtils.removeElement(shortArray, data.consumeShort()); + break; + case 80: + ArrayUtils.removeElement(strArray, data.consumeString(10)); + break; + case 81: + ArrayUtils.subarray(boolArray, 0, 1); + break; + case 82: + ArrayUtils.subarray(byteArray, 0, 1); + break; + case 83: + ArrayUtils.subarray(charArray, 0, 1); + break; + case 84: + ArrayUtils.subarray(doubleArray, 0, 1); + break; + case 85: + ArrayUtils.subarray(floatArray, 0, 1); + break; + case 86: + ArrayUtils.subarray(intArray, 0, 1); + break; + case 87: + ArrayUtils.subarray(longArray, 0, 1); + break; + case 88: + ArrayUtils.subarray(shortArray, 0, 1); + break; + case 89: + ArrayUtils.subarray(strArray, 0, 1); + break; + } + } + } catch (IllegalArgumentException e) { + // Known exception + } + } + + private static void cleanLargeArray() { + if (boolArray.length > 256) { + boolArray = new boolean[1]; + } + if (byteArray.length > 256) { + byteArray = new byte[1]; + ArrayFill.fill(byteArray, (byte) 0); + } + if (charArray.length > 256) { + charArray = new char[1]; + ArrayFill.fill(charArray, (char) 0); + } + if (doubleArray.length > 256) { + doubleArray = new double[1]; + ArrayFill.fill(doubleArray, 0d); + } + if (floatArray.length > 256) { + floatArray = new float[1]; + ArrayFill.fill(floatArray, 0f); + } + if (intArray.length > 256) { + intArray = new int[1]; + ArrayFill.fill(intArray, 0); + } + if (longArray.length > 256) { + longArray = new long[1]; + ArrayFill.fill(longArray, 0l); + } + if (shortArray.length > 256) { + shortArray = new short[1]; + ArrayFill.fill(shortArray, (short) 0); + } + if (strArray.length > 256) { + strArray = new String[1]; + ArrayFill.fill(strArray, ""); + } + + sortArray(); + } + + private static void sortArray() { + ArraySorter.sort(byteArray); + ArraySorter.sort(charArray); + ArraySorter.sort(doubleArray); + ArraySorter.sort(floatArray); + ArraySorter.sort(intArray); + ArraySorter.sort(longArray); + ArraySorter.sort(shortArray); + ArraySorter.sort(strArray); + } +} diff --git a/projects/apache-commons-lang/CharUtilsFuzzer.java b/projects/apache-commons-lang/CharUtilsFuzzer.java new file mode 100644 index 000000000000..bff6f12e0fb4 --- /dev/null +++ b/projects/apache-commons-lang/CharUtilsFuzzer.java @@ -0,0 +1,68 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.CharSequenceUtils; +import org.apache.commons.lang3.CharSetUtils; +import org.apache.commons.lang3.CharUtils; + +/** This fuzzer targets the methods of the Char related utils classes. */ +public class CharUtilsFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 10); + + switch (choice) { + case 1: + CharSequenceUtils.subSequence(data.consumeRemainingAsString(), 0); + break; + case 2: + CharSequenceUtils.toCharArray(data.consumeRemainingAsString()); + break; + case 3: + CharSetUtils.containsAny( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 4: + CharSetUtils.count( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 5: + CharSetUtils.delete( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 6: + CharSetUtils.keep( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 7: + CharSetUtils.squeeze( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 8: + CharUtils.isAsciiAlphanumeric(data.consumeChar()); + break; + case 9: + CharUtils.toCharacterObject(data.consumeRemainingAsString()); + break; + case 10: + CharUtils.unicodeEscaped(data.consumeChar()); + break; + } + } catch (IllegalArgumentException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/ConversionFuzzer.java b/projects/apache-commons-lang/ConversionFuzzer.java new file mode 100644 index 000000000000..b022550f82b8 --- /dev/null +++ b/projects/apache-commons-lang/ConversionFuzzer.java @@ -0,0 +1,79 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.Conversion; + +/** This fuzzer targets the methods of the Conversion class */ +public class ConversionFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 15); + Integer size = data.consumeInt(1, 5); + Integer remaining = data.remainingBytes(); + + switch (choice) { + case 1: + Conversion.binaryBeMsb0ToHexDigit(data.consumeBooleans(data.consumeInt(1, 5))); + break; + case 2: + Conversion.binaryToByte(data.consumeBooleans(size), 0, (byte) 0, 0, size); + break; + case 3: + Conversion.binaryToHexDigit(data.consumeBooleans(data.consumeInt(1, 5))); + break; + case 4: + Conversion.binaryToHexDigitMsb0_4bits(data.consumeBooleans(data.consumeInt(1, 5))); + break; + case 5: + Conversion.binaryToInt(data.consumeBooleans(data.consumeInt(1, 5)), 0, 0, 0, size); + break; + case 6: + Conversion.binaryToLong(data.consumeBooleans(data.consumeInt(1, 5)), 0, 0l, 0, size); + break; + case 7: + Conversion.binaryToShort( + data.consumeBooleans(data.consumeInt(1, 5)), 0, (short) 0, 0, size); + break; + case 8: + Conversion.byteArrayToInt(data.consumeRemainingAsBytes(), 0, 0, 0, remaining); + break; + case 9: + Conversion.byteArrayToLong(data.consumeRemainingAsBytes(), 0, 0l, 0, remaining); + break; + case 10: + Conversion.byteArrayToShort(data.consumeRemainingAsBytes(), 0, (short) 0, 0, remaining); + break; + case 11: + Conversion.byteArrayToUuid(data.consumeRemainingAsBytes(), 0); + break; + case 12: + Conversion.hexToByte(data.consumeRemainingAsString(), 0, (byte) 0, 0, remaining); + break; + case 13: + Conversion.hexToInt(data.consumeRemainingAsString(), 0, 0, 0, remaining); + break; + case 14: + Conversion.hexToLong(data.consumeRemainingAsString(), 0, 0l, 0, remaining); + break; + case 15: + Conversion.hexToShort(data.consumeRemainingAsString(), 0, (short) 0, 0, remaining); + break; + } + } catch (IllegalArgumentException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/DateUtilsFuzzer.java b/projects/apache-commons-lang/DateUtilsFuzzer.java new file mode 100644 index 000000000000..33c8a26059cd --- /dev/null +++ b/projects/apache-commons-lang/DateUtilsFuzzer.java @@ -0,0 +1,90 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import java.text.ParseException; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.lang3.time.DurationFormatUtils; + +/** This fuzzer targets the methods of the classes in the time package. */ +public class DateUtilsFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Calendar calendar = Calendar.getInstance(); + Date date = new Date(); + Integer choice = data.consumeInt(1, 13); + + switch (choice) { + case 1: + DateFormatUtils.format(calendar, data.consumeRemainingAsString()); + break; + case 2: + DateFormatUtils.formatUTC(date, data.consumeRemainingAsString()); + break; + case 3: + DateUtils.parseDate( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 4: + DateUtils.parseDate( + data.consumeString(data.remainingBytes()), + Locale.getDefault(), + data.consumeRemainingAsString()); + break; + case 5: + DateUtils.parseDateStrictly( + data.consumeString(data.remainingBytes()), data.consumeRemainingAsString()); + break; + case 6: + DateUtils.parseDateStrictly( + data.consumeString(data.remainingBytes()), + Locale.getDefault(), + data.consumeRemainingAsString()); + break; + case 7: + DateUtils.round(date, data.consumeInt()); + break; + case 8: + DateUtils.round(calendar, data.consumeInt()); + break; + case 9: + DateUtils.truncatedEquals( + calendar, DateUtils.truncate(calendar, data.consumeInt()), data.consumeInt()); + break; + case 10: + DateUtils.truncatedEquals( + date, DateUtils.truncate(date, data.consumeInt()), data.consumeInt()); + break; + case 11: + DurationFormatUtils.formatDuration(data.consumeLong(), data.consumeRemainingAsString()); + break; + case 12: + DurationFormatUtils.formatDurationWords( + data.consumeLong(), data.consumeBoolean(), data.consumeBoolean()); + break; + case 13: + DurationFormatUtils.formatPeriod( + data.consumeLong(), data.consumeLong(), data.consumeRemainingAsString()); + break; + } + } catch (ParseException | IllegalArgumentException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/FractionFuzzer.java b/projects/apache-commons-lang/FractionFuzzer.java new file mode 100644 index 000000000000..e176180f7ae9 --- /dev/null +++ b/projects/apache-commons-lang/FractionFuzzer.java @@ -0,0 +1,69 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.math.Fraction; + +/** This fuzzer targets the methods of the Fraction class in the math package. */ +public class FractionFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 10); + Integer intValue = data.consumeInt(); + Fraction fraction1 = Fraction.getFraction(data.consumeString(data.remainingBytes())); + Fraction fraction2 = Fraction.getFraction(data.consumeRemainingAsString()); + + switch (choice) { + case 1: + fraction1.abs(); + fraction2.abs(); + break; + case 2: + fraction1.add(fraction2); + break; + case 3: + fraction1.compareTo(fraction2); + break; + case 4: + fraction1.divideBy(fraction2); + break; + case 5: + fraction1.invert(); + fraction2.invert(); + break; + case 6: + fraction1.multiplyBy(fraction2); + break; + case 7: + fraction1.pow(intValue); + fraction2.pow(intValue); + break; + case 8: + fraction1.reduce(); + fraction2.reduce(); + break; + case 9: + fraction1.subtract(fraction2); + break; + case 10: + fraction1.toProperString(); + fraction2.toProperString(); + break; + } + } catch (NumberFormatException | ArithmeticException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/LocaleUtilsFuzzer.java b/projects/apache-commons-lang/LocaleUtilsFuzzer.java new file mode 100644 index 000000000000..7d49927cfc28 --- /dev/null +++ b/projects/apache-commons-lang/LocaleUtilsFuzzer.java @@ -0,0 +1,49 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import java.util.Locale; +import org.apache.commons.lang3.LocaleUtils; + +/** This fuzzer targets the methods of the LocaleUtils class in the base package. */ +public class LocaleUtilsFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 5); + String string = data.consumeString(data.remainingBytes()); + Locale locale = LocaleUtils.toLocale(LocaleUtils.toLocale(data.consumeRemainingAsString())); + + switch (choice) { + case 1: + LocaleUtils.countriesByLanguage(string); + break; + case 2: + LocaleUtils.isAvailableLocale(locale); + break; + case 3: + LocaleUtils.isLanguageUndetermined(locale); + break; + case 4: + LocaleUtils.languagesByCountry(string); + break; + case 5: + LocaleUtils.localeLookupList(locale); + break; + } + } catch (IllegalArgumentException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/MathUtilsFuzzer.java b/projects/apache-commons-lang/MathUtilsFuzzer.java new file mode 100644 index 000000000000..697185e8cb9b --- /dev/null +++ b/projects/apache-commons-lang/MathUtilsFuzzer.java @@ -0,0 +1,57 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.math.IEEE754rUtils; +import org.apache.commons.lang3.math.NumberUtils; + +/** This fuzzer targets the methods of the classes in the math package. */ +public class MathUtilsFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 5); + + switch (choice) { + case 1: + float[] floats = new float[data.consumeInt(1, 5)]; + for (Integer i = 0; i < floats.length; i++) { + floats[i] = data.consumeFloat(); + } + IEEE754rUtils.max(floats); + IEEE754rUtils.min(floats); + break; + case 2: + double[] doubles = new double[data.consumeInt(1, 5)]; + for (Integer i = 0; i < doubles.length; i++) { + doubles[i] = data.consumeDouble(); + } + IEEE754rUtils.max(doubles); + IEEE754rUtils.min(doubles); + break; + case 3: + NumberUtils.createNumber(data.consumeRemainingAsString()); + break; + case 4: + NumberUtils.isCreatable(data.consumeRemainingAsString()); + break; + case 5: + NumberUtils.isParsable(data.consumeRemainingAsString()); + break; + } + } catch (NumberFormatException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/SerializationUtilsFuzzer.java b/projects/apache-commons-lang/SerializationUtilsFuzzer.java new file mode 100644 index 000000000000..0ea838dab0cd --- /dev/null +++ b/projects/apache-commons-lang/SerializationUtilsFuzzer.java @@ -0,0 +1,45 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.SerializationException; +import org.apache.commons.lang3.SerializationUtils; + +/** This fuzzer targets the methods of the SerializationUtils class in the base package. */ +public class SerializationUtilsFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 4); + byte[] byteArray = data.consumeRemainingAsBytes(); + + switch (choice) { + case 1: + byteArray = SerializationUtils.clone(byteArray); + break; + case 2: + byteArray = SerializationUtils.roundtrip(byteArray); + break; + case 3: + byteArray = SerializationUtils.serialize(byteArray); + break; + case 4: + byteArray = SerializationUtils.deserialize(byteArray); + break; + } + } catch (SerializationException e) { + // Known exception + } + } +} diff --git a/projects/apache-commons-lang/StringUtilsFuzzer.java b/projects/apache-commons-lang/StringUtilsFuzzer.java new file mode 100644 index 000000000000..ee850e2bba7e --- /dev/null +++ b/projects/apache-commons-lang/StringUtilsFuzzer.java @@ -0,0 +1,222 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +import com.code_intelligence.jazzer.api.FuzzedDataProvider; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; + +/** This fuzzer targets the methods of the StringUtils class in the base package. */ +public class StringUtilsFuzzer { + public static void fuzzerTestOneInput(FuzzedDataProvider data) { + try { + Integer choice = data.consumeInt(1, 61); + String string1 = data.consumeString(data.remainingBytes()); + String string2 = data.consumeRemainingAsString(); + + switch (choice) { + case 1: + StringUtils.abbreviate(string1, string1.length()); + break; + case 2: + StringUtils.abbreviateMiddle(string1, string2, string1.length()); + break; + case 3: + StringUtils.appendIfMissing(string1, string2); + break; + case 4: + StringUtils.appendIfMissingIgnoreCase(string1, string2); + break; + case 5: + StringUtils.capitalize(string1); + break; + case 6: + StringUtils.center(string1, string1.length()); + break; + case 7: + StringUtils.chomp(string1); + break; + case 8: + StringUtils.chop(string1); + break; + case 9: + StringUtils.compare(string1, string2); + break; + case 10: + StringUtils.compareIgnoreCase(string1, string2); + break; + case 11: + StringUtils.contains(string1, string2); + break; + case 12: + StringUtils.containsAny(string1, string2); + break; + case 13: + StringUtils.containsAnyIgnoreCase(string1, string2); + break; + case 14: + StringUtils.containsNone(string1, string2); + break; + case 15: + StringUtils.containsOnly(string1, string2); + break; + case 16: + StringUtils.containsWhitespace(string1); + break; + case 17: + StringUtils.countMatches(string1, string2); + break; + case 18: + StringUtils.deleteWhitespace(string1); + break; + case 19: + StringUtils.difference(string1, string2); + break; + case 20: + StringUtils.endsWith(string1, string2); + break; + case 21: + StringUtils.endsWithAny(string1, string2); + break; + case 22: + StringUtils.endsWithIgnoreCase(string1, string2); + break; + case 23: + StringUtils.equals(string1, string2); + break; + case 24: + StringUtils.equalsAny(string1, string2); + break; + case 25: + StringUtils.equalsAnyIgnoreCase(string1, string2); + break; + case 26: + StringUtils.equalsIgnoreCase(string1, string2); + break; + case 27: + StringUtils.getCommonPrefix(string1, string2); + break; + case 28: + StringUtils.getDigits(string1); + break; + case 29: + StringUtils.indexOf(string1, string2); + break; + case 30: + StringUtils.indexOfAny(string1, string2); + break; + case 31: + StringUtils.indexOfAnyBut(string1, string2); + break; + case 32: + StringUtils.indexOfDifference(string1, string2); + break; + case 33: + StringUtils.indexOfIgnoreCase(string1, string2); + break; + case 34: + StringUtils.isAllBlank(string1, string2); + break; + case 35: + StringUtils.isAllEmpty(string1, string2); + break; + case 36: + StringUtils.isAllLowerCase(string1); + break; + case 37: + StringUtils.isAllUpperCase(string1); + break; + case 38: + StringUtils.isMixedCase(string1); + break; + case 39: + if (string2.length() > 0) { + StringUtils.join(string1.toCharArray(), string2.toCharArray()[0], 0, string1.length()); + } + break; + case 40: + if (string2.length() > 0) { + StringUtils.joinWith(string1, string2.toCharArray()); + } + break; + case 41: + StringUtils.lastIndexOf(string1, string2); + break; + case 42: + StringUtils.lastIndexOfAny(string1, string2); + break; + case 43: + StringUtils.lastIndexOfIgnoreCase(string1, string2); + break; + case 44: + StringUtils.left(string1, string1.length()); + break; + case 45: + StringUtils.leftPad(string1, string1.length() + 10); + break; + case 46: + StringUtils.mid(string1, 0, string1.length()); + break; + case 47: + StringUtils.normalizeSpace(string1); + break; + case 48: + StringUtils.overlay(string1, string2, 0, string1.length()); + break; + case 49: + StringUtils.right(string1, string1.length()); + break; + case 50: + StringUtils.rightPad(string1, string1.length() + 10); + break; + case 51: + StringUtils.rotate(string1, string1.length()); + break; + case 52: + StringUtils.split(string1); + break; + case 53: + StringUtils.splitByCharacterType(string1); + break; + case 54: + StringUtils.splitByCharacterTypeCamelCase(string1); + break; + case 55: + StringUtils.splitByWholeSeparator(string1, string2); + break; + case 56: + StringUtils.splitPreserveAllTokens(string1); + break; + case 57: + StringUtils.swapCase(string1); + break; + case 58: + StringUtils.truncate(string1, string1.length()); + break; + case 59: + StringUtils.uncapitalize(string1); + break; + case 60: + StringUtils.wrap(string1, string2); + break; + case 61: + // TODO verify if regex injection is real + // Validate.matchesPattern(string1, string2); + break; + } + } catch (IllegalArgumentException e) { + // Known exception + } + } +}