1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import com.code_intelligence.jazzer.api.FuzzedDataProvider; 18 import java.io.IOException; 19 import org.brotli.wrapper.enc.Encoder; 20 21 public class BrotliJavaCompressFuzzer { 22 static { 23 System.loadLibrary("brotli_encoder_jni"); 24 } fuzzerTestOneInput(FuzzedDataProvider data)25 public static void fuzzerTestOneInput(FuzzedDataProvider data) throws IOException{ 26 // quality range for brotli is limited in the original library 27 int quality = data.consumeInt(-1, 11); 28 // similar to quality, window size is also limited 29 int lgwin = data.consumeInt(10, 24); 30 31 boolean pickDefaultWin = data.consumeBoolean(); 32 if (pickDefaultWin) { 33 lgwin = -1; 34 } 35 36 byte[] rawData = data.consumeRemainingAsBytes(); 37 Encoder.Parameters params = new Encoder.Parameters(); 38 params.setQuality(quality); 39 params.setWindow(lgwin); 40 Encoder.compress(rawData, params); 41 } 42 } 43