-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial integration of Junrar (#7750)
initial integration of junrar
- Loading branch information
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2022 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://services.gradle.org/distributions/gradle-7.4.2-bin.zip -o gradle.zip && \ | ||
unzip gradle.zip -d $SRC/gradle && \ | ||
rm -rf gradle.zip | ||
|
||
ENV GRADLE_HOME $SRC/gradle/gradle-7.4.2 | ||
ENV PATH $GRADLE_HOME/bin:$PATH | ||
|
||
# Dict | ||
# no existing rar.dict found on web, build rar dict manually later | ||
|
||
# Seeds | ||
RUN git clone --depth 1 https://github.com/strongcourage/fuzzing-corpus.git && \ | ||
zip -j $SRC/JunrarFuzzer_seed_corpus.zip fuzzing-corpus/rar/* && \ | ||
rm -rf fuzzing-corpus | ||
|
||
RUN git clone --depth 1 https://github.com/junrar/junrar.git junrar | ||
|
||
COPY build.sh $SRC/ | ||
COPY JunrarFuzzer.java $SRC/ | ||
WORKDIR $SRC/junrar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2022 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.InputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.ByteArrayInputStream; | ||
|
||
import com.github.junrar.Archive; | ||
import com.github.junrar.rarfile.FileHeader; | ||
import com.github.junrar.exception.RarException; | ||
import com.github.junrar.io.SeekableReadOnlyByteChannel; | ||
import com.github.junrar.rarfile.MainHeader; | ||
import com.github.junrar.volume.Volume; | ||
|
||
public class JunrarFuzzer { | ||
public static void fuzzerTestOneInput(FuzzedDataProvider data) { | ||
|
||
try { | ||
InputStream inputStream = new ByteArrayInputStream(data.consumeRemainingAsBytes()); | ||
Archive v0 = null; | ||
FileHeader v1 = null; | ||
SeekableReadOnlyByteChannel v2 = null; | ||
MainHeader v3 = null; | ||
Volume v4 = null; | ||
|
||
v0 = new Archive(inputStream); | ||
v2 = v0.getChannel(); | ||
if (v2 != null) { | ||
v2.getPosition(); | ||
} | ||
|
||
v0.getFileHeaders(); | ||
v0.getHeaders(); | ||
|
||
v3 = v0.getMainHeader(); | ||
if (v3 != null) { | ||
v3.getEncryptVersion(); | ||
v3.isEncrypted(); | ||
//v3.print(); | ||
} | ||
|
||
v4 = v0.getVolume(); | ||
if (v4 != null) { | ||
v4.getChannel(); | ||
v4.getLength(); | ||
} | ||
|
||
v0.isEncrypted(); | ||
|
||
while (true) { | ||
v1 = v0.nextFileHeader(); | ||
if (v1 == null) { | ||
break; | ||
} | ||
|
||
v1.getCTime(); | ||
v1.hasVolumeNumber(); | ||
v1.isSubBlock(); | ||
|
||
v0.extractFile(v1, OutputStream.nullOutputStream()); | ||
} | ||
|
||
} catch (IOException e1) { | ||
} catch (RarException e2) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash -eu | ||
# Copyright 2022 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. | ||
# | ||
################################################################################ | ||
|
||
mv $SRC/*.zip $OUT | ||
#mv $SRC/{*.zip,*.dict} $OUT | ||
|
||
./gradlew build | ||
CURRENT_VERSION=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}') | ||
cp "build/libs/junrar-$CURRENT_VERSION-sources.jar" $OUT/junrar.jar | ||
|
||
curl -L https://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar -o $OUT/slf4j-api.jar | ||
curl -L https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar -o $OUT/slf4j-simple.jar | ||
|
||
ALL_JARS="junrar.jar slf4j-api.jar slf4j-simple.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 | ||
|
||
# All .jar and .class files lie in the same directory as the fuzzer at runtime. | ||
RUNTIME_CLASSPATH=$(echo $ALL_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir | ||
|
||
for fuzzer in $(find $SRC -name '*Fuzzer.java'); do | ||
fuzzer_basename=$(basename -s .java $fuzzer) | ||
javac -cp $BUILD_CLASSPATH $fuzzer | ||
cp $SRC/$fuzzer_basename.class $OUT/ | ||
|
||
# Create an execution wrapper that executes Jazzer with the correct arguments. | ||
echo "#!/bin/sh | ||
# LLVMFuzzerTestOneInput for fuzzer detection. | ||
this_dir=\$(dirname \"\$0\") | ||
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=\"-Xmx2048m\" \ | ||
\$@" > $OUT/$fuzzer_basename | ||
chmod u+x $OUT/$fuzzer_basename | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fuzzing_engines: | ||
- libfuzzer | ||
homepage: https://github.com/junrar/junrar | ||
language: jvm | ||
main_repo: https://github.com/junrar/junrar.git | ||
sanitizers: | ||
- address | ||
vendor_ccs: | ||
- [email protected] |