Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve speed of fuzzer_seek #766

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions oss-fuzz/seek.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "common.h"

int write_abort_check_counter = -1;
int written_uncompressed_bytes = 0;
int errors_received_counter = 0;

#if 0 /* set to 1 to debug */
#define FPRINTF_DEBUG_ONLY(...) fprintf(__VA_ARGS__)
Expand All @@ -46,20 +48,30 @@ int write_abort_check_counter = -1;

static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data)
{
(void)decoder, (void)frame, (void)buffer, (void)client_data;
(void)decoder, (void)buffer, (void)client_data;
if(write_abort_check_counter > 0) {
write_abort_check_counter--;
if(write_abort_check_counter == 0)
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
} else if(write_abort_check_counter == 0)
/* This must not happen: write callback called after abort is returned */
abort();

written_uncompressed_bytes += frame->header.blocksize * frame->header.channels * frame->header.bits_per_sample / 8;
if(written_uncompressed_bytes > (1 << 24))
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;


if(errors_received_counter > 10000)
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;

return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}

static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus error, void *client_data)
{
(void)decoder, (void)error, (void)client_data;
(void)decoder, (void)error, (void)client_data;
errors_received_counter++;
}


Expand All @@ -80,6 +92,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
alloc_check_counter = 0;

write_abort_check_counter = -1;
written_uncompressed_bytes = 0;
errors_received_counter = 0;

/* allocate the decoder */
if((decoder = FLAC__stream_decoder_new()) == NULL) {
Expand Down
5 changes: 5 additions & 0 deletions src/libFLAC/stream_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,11 @@ FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, uint32_t size, uint32_
decoder->private_->side_subframe = 0;
}

/* Only grow per-channel buffers, even if number of channels increases */
if(decoder->private_->output_capacity > size) {
size = decoder->private_->output_capacity;
}

for(i = 0; i < channels; i++) {
/* WATCHOUT:
* FLAC__lpc_restore_signal_asm_ia32_mmx() and ..._intrin_sseN()
Expand Down
Loading