From 9e8d7389dc43cc9e53a71a3e8e30f87020367187 Mon Sep 17 00:00:00 2001 From: Martijn van Beurden Date: Wed, 18 May 2022 11:04:45 +0200 Subject: [PATCH] Fix initialization of decoder fuzzer The decoder fuzzer initialized before setting up. This is now swapped without upsetting the way the datasource is queried --- oss-fuzz/fuzzer_decoder.cc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/oss-fuzz/fuzzer_decoder.cc b/oss-fuzz/fuzzer_decoder.cc index ee4fdea1..da88c3df 100644 --- a/oss-fuzz/fuzzer_decoder.cc +++ b/oss-fuzz/fuzzer_decoder.cc @@ -171,22 +171,12 @@ namespace FLAC { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { fuzzing::datasource::Datasource ds(data, size); FLAC::Decoder::FuzzerStream decoder(ds); + bool use_ogg = true; try { - { - ::FLAC__StreamDecoderInitStatus ret; - - if ( ds.Get() ) { - ret = decoder.init(); - } else { - ret = decoder.init_ogg(); - } - - if ( ret != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { - goto end; - } + if ( ds.Get() ) { + use_ogg = false; } - if ( ds.Get() ) { #ifdef FUZZER_DEBUG printf("set_ogg_serial_number\n"); @@ -245,6 +235,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { #endif decoder.set_metadata_ignore_all(); } + { + ::FLAC__StreamDecoderInitStatus ret; + if ( !use_ogg ) { + ret = decoder.init(); + } else { + ret = decoder.init_ogg(); + } + + if ( ret != FLAC__STREAM_DECODER_INIT_STATUS_OK ) { + goto end; + } + } while ( ds.Get() ) { switch ( ds.Get() ) {