From 582afee215078ab26815fc01fd18abaa406933d1 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Mon, 9 Mar 2026 14:52:58 +0530 Subject: [PATCH 1/2] calcite-avatica: Transition to Ideal Integration (upstream source) --- projects/calcite-avatica/build.sh | 53 ++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/projects/calcite-avatica/build.sh b/projects/calcite-avatica/build.sh index aa4d8ad499a2..4e1e859ac9fd 100644 --- a/projects/calcite-avatica/build.sh +++ b/projects/calcite-avatica/build.sh @@ -15,31 +15,46 @@ # ########################################################################## -# Gradle build with gradle wrapper +# Clean up caches rm -rf $HOME/.gradle/caches/ -./gradlew clean build shadowJar -x test + +# Build project and copy dependencies +./gradlew clean :core:jar :core:testClasses :core:copyFuzzDependencies -x test ./gradlew --stop +# Find version CURRENT_VERSION=$(./gradlew properties | grep ^version: | cut -d" " -f2) -cp "./shaded/core/build/libs/avatica-$CURRENT_VERSION-shadow.jar" $OUT/avatica.jar -ALL_JARS="avatica.jar" -# The classpath at build-time includes the project jars in $OUT as well as the -# Jazzer API. -BUILD_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH +# Copy jars to $OUT +cp core/build/fuzz-dependencies/*.jar $OUT/ +cp core/build/libs/avatica-core-$CURRENT_VERSION.jar $OUT/avatica-core.jar +cp metrics/build/libs/avatica-metrics-$CURRENT_VERSION.jar $OUT/avatica-metrics.jar + +# Copy fuzzer classes to $OUT (preserving package structure) +cp -r core/build/classes/java/test/* $OUT/ + +# Create a consolidated list of all jars for the classpath +ALL_JARS=$(find $OUT -maxdepth 1 -name "*.jar" | xargs -n1 basename) -# All .jar and .class files lie in the same directory as the fuzzer at runtime. +# The runtime classpath will include all jars in $OUT and the this_dir itself for classes RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir -for fuzzer in $(find $SRC -maxdepth 1 -name '*Fuzzer.java') -do - fuzzer_basename=$(basename -s .java $fuzzer) - javac -cp $BUILD_CLASSPATH $fuzzer - cp $SRC/$fuzzer_basename.class $OUT/ +# List of fuzzer targets +FUZZERS=( + "org.apache.calcite.avatica.fuzz.AvaticaSiteFuzzer" + "org.apache.calcite.avatica.fuzz.JsonHandlerFuzzer" + "org.apache.calcite.avatica.fuzz.ProtobufHandlerFuzzer" + "org.apache.calcite.avatica.fuzz.TypedValueFuzzer" + "org.apache.calcite.avatica.fuzz.Base64Fuzzer" + "org.apache.calcite.avatica.fuzz.ConnectStringParserFuzzer" +) - # Create an execution wrapper that executes Jazzer with the correct arguments. +# For each fuzzer, create a wrapper script +for target_class in "${FUZZERS[@]}" +do + fuzzer_basename=$(echo $target_class | awk -F. '{print $NF}') + echo "#!/bin/bash - # LLVMFuzzerTestOneInput for fuzzer detection. this_dir=\$(dirname "\$0") if [[ "\$@" =~ (^| )-runs=[0-9]+($| ) ]] @@ -49,13 +64,13 @@ do mem_settings='-Xmx2048m:-Xss1024k' fi - LD_LIBRARY_PATH="$JVM_LD_LIBRARY_PATH":\$this_dir \ + LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ \$this_dir/jazzer_driver \ --agent_path=\$this_dir/jazzer_agent_deploy.jar \ --cp=$RUNTIME_CLASSPATH \ - --target_class=$fuzzer_basename \ - --jvm_args="\$mem_settings" \ + --target_class=$target_class \ + --jvm_args=\"\$mem_settings\" \ \$@" > $OUT/$fuzzer_basename - chmod u+x $OUT/$fuzzer_basename + chmod u+x $OUT/$fuzzer_basename done From 2fc796e8eaf72e018b356a9a18a7611fff236775 Mon Sep 17 00:00:00 2001 From: Vishal S Date: Mon, 9 Mar 2026 15:18:44 +0530 Subject: [PATCH 2/2] calcite-avatica: Implement dynamic fuzzer discovery and clean up Dockerfile --- projects/calcite-avatica/Base64Fuzzer.java | 36 ------------------- .../ConnectStringParserFuzzer.java | 33 ----------------- projects/calcite-avatica/Dockerfile | 2 +- projects/calcite-avatica/build.sh | 16 +++------ 4 files changed, 6 insertions(+), 81 deletions(-) delete mode 100644 projects/calcite-avatica/Base64Fuzzer.java delete mode 100644 projects/calcite-avatica/ConnectStringParserFuzzer.java diff --git a/projects/calcite-avatica/Base64Fuzzer.java b/projects/calcite-avatica/Base64Fuzzer.java deleted file mode 100644 index 2f2cb51ed540..000000000000 --- a/projects/calcite-avatica/Base64Fuzzer.java +++ /dev/null @@ -1,36 +0,0 @@ -// 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.io.IOException; -import org.apache.calcite.avatica.util.Base64; - -// Generated with https://github.com/ossf/fuzz-introspector/tree/main/tools/auto-fuzz -// Minor modifications to beautify code and ensure exception is caught. -// Heuristic name: jvm-autofuzz-heuristics-1 -// Target method: [org.apache.calcite.avatica.util.Base64] public static java.lang.String encodeBytes(byte[],int) throws java.io.IOException -public class Base64Fuzzer { - public static void fuzzerTestOneInput(FuzzedDataProvider data) { - try { - if (data.consumeBoolean()) { - Base64.encodeBytes(data.consumeRemainingAsBytes()); - } else { - Base64.decode(data.consumeRemainingAsBytes()); - } - } catch (IOException | IllegalArgumentException e) { - // Known exception - } - } -} diff --git a/projects/calcite-avatica/ConnectStringParserFuzzer.java b/projects/calcite-avatica/ConnectStringParserFuzzer.java deleted file mode 100644 index 282c6d3c9ddd..000000000000 --- a/projects/calcite-avatica/ConnectStringParserFuzzer.java +++ /dev/null @@ -1,33 +0,0 @@ -// 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.sql.SQLException; -import java.util.Properties; -import org.apache.calcite.avatica.ConnectStringParser; - -// Generated with https://github.com/ossf/fuzz-introspector/tree/main/tools/auto-fuzz -// Minor modifications to beautify code and ensure exception is caught. -// Heuristic name: jvm-autofuzz-heuristics-1 -// Target method: [org.apache.calcite.avatica.ConnectStringParser] public static java.util.Properties parse(java.lang.String) throws java.sql.SQLException -public class ConnectStringParserFuzzer { - public static void fuzzerTestOneInput(FuzzedDataProvider data) { - try { - ConnectStringParser.parse(data.consumeRemainingAsString()); - } catch (SQLException e) { - // Known exception - } - } -} diff --git a/projects/calcite-avatica/Dockerfile b/projects/calcite-avatica/Dockerfile index cd492ad27b49..880b47070ef5 100644 --- a/projects/calcite-avatica/Dockerfile +++ b/projects/calcite-avatica/Dockerfile @@ -15,5 +15,5 @@ ########################################################################## FROM gcr.io/oss-fuzz-base/base-builder-jvm RUN git clone --depth 1 https://github.com/apache/calcite-avatica calcite-avatica -COPY *.sh *.java $SRC/ +COPY *.sh $SRC/ WORKDIR $SRC/calcite-avatica diff --git a/projects/calcite-avatica/build.sh b/projects/calcite-avatica/build.sh index 4e1e859ac9fd..17cc52e0266e 100644 --- a/projects/calcite-avatica/build.sh +++ b/projects/calcite-avatica/build.sh @@ -39,20 +39,14 @@ ALL_JARS=$(find $OUT -maxdepth 1 -name "*.jar" | xargs -n1 basename) # The runtime classpath will include all jars in $OUT and the this_dir itself for classes RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir -# List of fuzzer targets -FUZZERS=( - "org.apache.calcite.avatica.fuzz.AvaticaSiteFuzzer" - "org.apache.calcite.avatica.fuzz.JsonHandlerFuzzer" - "org.apache.calcite.avatica.fuzz.ProtobufHandlerFuzzer" - "org.apache.calcite.avatica.fuzz.TypedValueFuzzer" - "org.apache.calcite.avatica.fuzz.Base64Fuzzer" - "org.apache.calcite.avatica.fuzz.ConnectStringParserFuzzer" -) +# Dynamically find all fuzzer classes in the specified package +FUZZER_CLASSES_DIR="$OUT/org/apache/calcite/avatica/fuzz" +FUZZERS=$(find "$FUZZER_CLASSES_DIR" -maxdepth 1 -name "*Fuzzer.class" -exec basename {} .class \;) # For each fuzzer, create a wrapper script -for target_class in "${FUZZERS[@]}" +for fuzzer_basename in $FUZZERS do - fuzzer_basename=$(echo $target_class | awk -F. '{print $NF}') + target_class="org.apache.calcite.avatica.fuzz.$fuzzer_basename" echo "#!/bin/bash # LLVMFuzzerTestOneInput for fuzzer detection.