mirror of https://github.com/google/oss-fuzz.git
opencensus-java: Initial integration (#10003)
This commit is contained in:
parent
1d4c89284b
commit
8a5cbcea37
|
@ -0,0 +1,4 @@
|
|||
project-parent/opencensus-java
|
||||
project-parent/fuzz-targets/target
|
||||
project-parent/fuzz-targets/src/test/resources
|
||||
project-parent/fuzz-targets/pom.xml.versionsBackup
|
|
@ -0,0 +1,34 @@
|
|||
# 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.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
FROM gcr.io/oss-fuzz-base/base-builder-jvm
|
||||
|
||||
RUN curl -L https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip && \
|
||||
unzip maven.zip -d $SRC/maven && \
|
||||
rm -rf maven.zip
|
||||
|
||||
ENV MVN $SRC/maven/apache-maven-3.6.3/bin/mvn
|
||||
|
||||
# if not set python infra helper cannot be used for local testing
|
||||
|
||||
COPY project-parent $SRC/project-parent/
|
||||
|
||||
RUN rm -rf $SRC/project-parent/opencensus-java
|
||||
RUN apt update && apt install -y openjdk-8-jdk
|
||||
RUN git clone --depth 1 https://github.com/census-instrumentation/opencensus-java/ $SRC/project-parent/opencensus-java
|
||||
|
||||
COPY build.sh $SRC/
|
||||
WORKDIR $SRC/
|
|
@ -0,0 +1,125 @@
|
|||
#!/bin/bash -eu
|
||||
# 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.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
PROJECT=opencensus-java
|
||||
PROJECT_GROUP_ID=io.opencensus
|
||||
PROJECT_ARTIFACT_ID=opencensus-api
|
||||
MAIN_REPOSITORY=https://github.com/census-instrumentation/opencensus-java/
|
||||
MAVEN_ARGS="-Djavac.src.version=8 -Djavac.target.version=8 -Denforcer.skip=true -DskipTests"
|
||||
GRADLE_ARGS="-x javadoc -x test"
|
||||
|
||||
function set_project_version_in_fuzz_targets_dependency {
|
||||
PROJECT_VERSION=$(cd $PROJECT && $MVN org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout)
|
||||
# set dependency project version in fuzz-targets
|
||||
(cd fuzz-targets && $MVN versions:use-dep-version -Dincludes=$PROJECT_GROUP_ID:$PROJECT_ARTIFACT_ID -DdepVersion=$PROJECT_VERSION -DforceVersion=true)
|
||||
}
|
||||
|
||||
cd project-parent
|
||||
|
||||
pushd $PROJECT
|
||||
export OPENCENSUS_JAVA_VERSION=$(awk '$1 ~ /version/ {print $3}' build.gradle | sed 's/"//g')
|
||||
popd
|
||||
|
||||
# LOCAL_DEV env variable need to be set in local development env
|
||||
if [[ -v LOCAL_DEV ]]; then
|
||||
MVN=mvn
|
||||
|
||||
# checkout latest project version
|
||||
git -C $PROJECT pull || git clone $MAIN_REPOSITORY $PROJECT
|
||||
|
||||
# set_project_version_in_fuzz_targets_dependency
|
||||
|
||||
#install
|
||||
# mvn -pl $PROJECT install -DskipTests
|
||||
(cd $PROJECT && ./gradlew build $GRADLE_ARGS)
|
||||
mvn -pl fuzz-targets install
|
||||
|
||||
else
|
||||
# Move seed corpus and dictionary.
|
||||
# mv $SRC/{*.zip,*.dict} $OUT
|
||||
|
||||
export JAVA_HOME="$OUT/open-jdk-8"
|
||||
mkdir -p $JAVA_HOME
|
||||
rsync -aL --exclude=*.zip "/usr/lib/jvm/java-8-openjdk-amd64/" "$JAVA_HOME"
|
||||
|
||||
(cd $PROJECT && ./gradlew build $GRADLE_ARGS)
|
||||
cp $SRC/project-parent/opencensus-java/api/build/libs/opencensus-api-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-api.jar
|
||||
cp $SRC/project-parent/opencensus-java/impl/build/libs/opencensus-impl-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-impl.jar
|
||||
cp $SRC/project-parent/opencensus-java/impl_core/build/libs/opencensus-impl-core-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-impl-core.jar
|
||||
cp $SRC/project-parent/opencensus-java/exporters/trace/util/build/libs/opencensus-exporter-trace-util-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-exporter-trace-util.jar
|
||||
cp $SRC/project-parent/opencensus-java/exporters/trace/ocagent/build/libs/opencensus-exporter-trace-ocagent-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-exporter-trace-ocagent.jar
|
||||
cp $SRC/project-parent/opencensus-java/contrib/resource_util/build/libs/opencensus-contrib-resource-util-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-contrib-resource-util.jar
|
||||
cp $SRC/project-parent/opencensus-java/exporters/trace/elasticsearch/build/libs/opencensus-exporter-trace-elasticsearch-$OPENCENSUS_JAVA_VERSION.jar $OUT/opencensus-exporter-trace-elasticsearch.jar
|
||||
|
||||
ALL_JARS="opencensus-api.jar opencensus-impl.jar opencensus-impl-core.jar opencensus-exporter-trace-util.jar opencensus-contrib-resource-util.jar opencensus-exporter-trace-elasticsearch.jar"
|
||||
|
||||
for fuzzer in $(find $SRC/project-parent/fuzz-targets -name '*Fuzzer.java' ! -name JsonConversionFuzzer.java); do
|
||||
$MVN -pl fuzz-targets install -Dmaven.repo.local=$OUT/m2
|
||||
$MVN -pl fuzz-targets dependency:build-classpath -Dmdep.outputFile=cp.txt -Dmaven.repo.local=$OUT/m2
|
||||
cp -r $SRC/project-parent/fuzz-targets/target/test-classes/ $OUT/
|
||||
RUNTIME_CLASSPATH_ABSOLUTE="$(echo $ALL_JARS | xargs printf -- "$OUT/%s:"):$(cat fuzz-targets/cp.txt):$OUT/test-classes"
|
||||
RUNTIME_CLASSPATH_RELATIVE=$(echo $RUNTIME_CLASSPATH_ABSOLUTE | sed "s|$OUT|.|g")
|
||||
|
||||
fuzzer_basename=$(basename -s .java $fuzzer)
|
||||
|
||||
# Create an execution wrapper for every fuzztarget
|
||||
echo "#!/bin/bash
|
||||
# LLVMFuzzerTestOneInput comment for fuzzer detection by infrastructure.
|
||||
if [[ \"\$@\" =~ (^| )-runs=[0-9]+($| ) ]]; then
|
||||
mem_settings='-Xmx1900m -Xss900k'
|
||||
else
|
||||
mem_settings='-Xmx2048m -Xss1024k'
|
||||
fi
|
||||
JAVA_HOME=\"\$this_dir/open-jdk-8/\" \
|
||||
./open-jdk-8/bin/java -cp $RUNTIME_CLASSPATH_RELATIVE \
|
||||
\$mem_settings \
|
||||
com.code_intelligence.jazzer.Jazzer \
|
||||
--target_class=com.example.$fuzzer_basename \
|
||||
\$@" > $OUT/$fuzzer_basename
|
||||
chmod u+x $OUT/$fuzzer_basename
|
||||
done
|
||||
|
||||
|
||||
PACKAGE_NAME="io.opencensus.exporter.trace.elasticsearch"
|
||||
PACKAGE_DIR=$SRC/project-parent/fuzz-targets/src/test/java/$(echo $PACKAGE_NAME | sed 's/\./\//g')
|
||||
mkdir -p $PACKAGE_DIR
|
||||
mv $SRC/project-parent/fuzz-targets/src/test/java/com/example/JsonConversionFuzzer.java $PACKAGE_DIR
|
||||
|
||||
$MVN -pl fuzz-targets install -Dmaven.repo.local=$OUT/m2
|
||||
$MVN -pl fuzz-targets dependency:build-classpath -Dmdep.outputFile=cp.txt -Dmaven.repo.local=$OUT/m2
|
||||
cp -r $SRC/project-parent/fuzz-targets/target/test-classes/ $OUT/
|
||||
RUNTIME_CLASSPATH_ABSOLUTE="$(cat fuzz-targets/cp.txt):$OUT/test-classes:$PACKAGE_NAME:$(echo $ALL_JARS | xargs printf -- "$OUT/%s:")."
|
||||
RUNTIME_CLASSPATH_RELATIVE=$(echo $RUNTIME_CLASSPATH_ABSOLUTE | sed "s|$OUT|.|g")
|
||||
|
||||
echo "#!/bin/bash
|
||||
# LLVMFuzzerTestOneInput comment for fuzzer detection by infrastructure.
|
||||
if [[ \"\$@\" =~ (^| )-runs=[0-9]+($| ) ]]; then
|
||||
mem_settings='-Xmx1900m -Xss900k'
|
||||
else
|
||||
mem_settings='-Xmx2048m -Xss1024k'
|
||||
fi
|
||||
JAVA_HOME=\"\$this_dir/open-jdk-8/\" \
|
||||
./open-jdk-8/bin/java -cp $RUNTIME_CLASSPATH_RELATIVE \
|
||||
\$mem_settings \
|
||||
com.code_intelligence.jazzer.Jazzer \
|
||||
--target_class=$PACKAGE_NAME.JsonConversionFuzzer \
|
||||
\$@" > $OUT/JsonConversionFuzzer
|
||||
chmod u+x $OUT/JsonConversionFuzzer
|
||||
|
||||
rm -rf $PACKAGE_DIR
|
||||
|
||||
fi
|
|
@ -0,0 +1,134 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.fuzzer</groupId>
|
||||
<artifactId>fuzz-targets</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>fuzz</name>
|
||||
<description>fuzz</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.code-intelligence</groupId>
|
||||
<artifactId>jazzer-junit</artifactId>
|
||||
<version>0.16.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<version>1.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-api</artifactId>
|
||||
<version>${env.OPENCENSUS_JAVA_VERSION}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../opencensus-java/api/build/libs/opencensus-api-0.32.0-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-impl</artifactId>
|
||||
<version>${env.OPENCENSUS_JAVA_VERSION}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../opencensus-java/impl/build/libs/opencensus-impl-0.32.0-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-impl-core</artifactId>
|
||||
<version>${env.OPENCENSUS_JAVA_VERSION}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../opencensus-java/impl_core/build/libs/opencensus-impl-core-0.32.0-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-exporter-trace-util</artifactId>
|
||||
<version>${env.OPENCENSUS_JAVA_VERSION}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../opencensus-java/exporters/trace/util/build/libs/opencensus-exporter-trace-util-0.32.0-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-contrib-resource-util</artifactId>
|
||||
<version>${env.OPENCENSUS_JAVA_VERSION}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../opencensus-java/contrib/resource_util/build/libs/opencensus-contrib-resource-util-0.32.0-SNAPSHOT.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-exporter-trace-elasticsearch</artifactId>
|
||||
<version>${env.OPENCENSUS_JAVA_VERSION}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/../opencensus-java/exporters/trace/elasticsearch/build/libs/opencensus-exporter-trace-elasticsearch-${env.OPENCENSUS_JAVA_VERSION}.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.opencensus</groupId>
|
||||
<artifactId>opencensus-proto</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>4.0.0-rc-2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.4.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-context</artifactId>
|
||||
<version>1.54.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${project.basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,100 @@
|
|||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package io.opencensus.exporter.trace.elasticsearch;
|
||||
|
||||
import com.code_intelligence.jazzer.api.FuzzedDataProvider;
|
||||
import com.code_intelligence.jazzer.junit.FuzzTest;
|
||||
|
||||
import io.opencensus.exporter.trace.elasticsearch.JsonConversionUtils;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.opencensus.common.Timestamp;
|
||||
import io.opencensus.trace.Annotation;
|
||||
import io.opencensus.trace.AttributeValue;
|
||||
import io.opencensus.trace.Link;
|
||||
import io.opencensus.trace.MessageEvent;
|
||||
import io.opencensus.trace.MessageEvent.Type;
|
||||
import io.opencensus.trace.SpanContext;
|
||||
import io.opencensus.trace.SpanId;
|
||||
import io.opencensus.trace.Status;
|
||||
import io.opencensus.trace.TraceId;
|
||||
import io.opencensus.trace.TraceOptions;
|
||||
import io.opencensus.trace.Tracestate;
|
||||
import io.opencensus.trace.export.SpanData;
|
||||
import io.opencensus.trace.export.SpanData.Attributes;
|
||||
import io.opencensus.trace.export.SpanData.Links;
|
||||
import io.opencensus.trace.export.SpanData.TimedEvent;
|
||||
import io.opencensus.trace.export.SpanData.TimedEvents;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonConversionFuzzer {
|
||||
static List<SpanData> spanDataList;
|
||||
|
||||
@FuzzTest
|
||||
void myFuzzTest(FuzzedDataProvider data) {
|
||||
spanDataList = new ArrayList<SpanData>();
|
||||
|
||||
String name = data.consumeString(200);
|
||||
String traceId = data.consumeString(200);
|
||||
String spanId = data.consumeString(200);
|
||||
String parentSpanId = data.consumeString(200);
|
||||
String spanName = data.consumeString(200);
|
||||
String key = data.consumeString(200);
|
||||
String value = data.consumeString(200);
|
||||
boolean isSampled = data.consumeBoolean();
|
||||
boolean hasRemoteParent = data.consumeBoolean();
|
||||
|
||||
try {
|
||||
List<TimedEvent<MessageEvent>> messageEvents =
|
||||
ImmutableList.of(
|
||||
TimedEvent.create(
|
||||
Timestamp.create(data.consumeInt(), data.consumeInt()),
|
||||
MessageEvent.builder(Type.RECEIVED, 0).setCompressedMessageSize(data.consumeInt()).build()),
|
||||
TimedEvent.create(
|
||||
Timestamp.create(data.consumeInt(), data.consumeInt()),
|
||||
MessageEvent.builder(Type.SENT, 0).setCompressedMessageSize(data.consumeInt()).build()));
|
||||
|
||||
SpanData spanData =
|
||||
SpanData.create(
|
||||
SpanContext.create(
|
||||
TraceId.fromLowerBase16(traceId),
|
||||
SpanId.fromLowerBase16(spanId),
|
||||
TraceOptions.builder().setIsSampled(isSampled).build(),
|
||||
Tracestate.builder().build()),
|
||||
SpanId.fromLowerBase16(parentSpanId),
|
||||
hasRemoteParent,
|
||||
spanName,
|
||||
null,
|
||||
Timestamp.create(data.consumeInt(), data.consumeInt()),
|
||||
Attributes.create(ImmutableMap.of(key, AttributeValue.stringAttributeValue(value)), 0),
|
||||
TimedEvents.create(Collections.emptyList(), 0),
|
||||
TimedEvents.create(messageEvents, 0),
|
||||
Links.create(Collections.<Link>emptyList(), 0),
|
||||
null,
|
||||
Status.OK,
|
||||
Timestamp.create(data.consumeInt(), data.consumeInt()));
|
||||
|
||||
spanDataList.add(spanData);
|
||||
List<String> json = JsonConversionUtils.convertToJson(name, spanDataList);
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.fuzzer</groupId>
|
||||
<artifactId>project-parent</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<!-- <module>opencensus-java</module> -->
|
||||
<module>fuzz-targets</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
homepage: "https://opencensus.io/"
|
||||
language: jvm
|
||||
fuzzing_engines:
|
||||
- libfuzzer
|
||||
main_repo: "https://github.com/census-instrumentation/opencensus-java/"
|
||||
sanitizers:
|
||||
- address
|
||||
vendor_ccs:
|
||||
- "wagner@code-intelligence.com"
|
||||
- "yakdan@code-intelligence.com"
|
||||
- "glendowne@code-intelligence.com"
|
||||
- "patrice.salathe@code-intelligence.com"
|
||||
- "hlin@code-intelligence.com"
|
||||
- "bug-disclosure@code-intelligence.com"
|
||||
run_tests: False
|
Loading…
Reference in New Issue