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

Speed up fuzzer_tool_flac #770

Merged
merged 2 commits into from
Dec 4, 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
12 changes: 6 additions & 6 deletions src/libFLAC/bitwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ typedef FLAC__uint64 FLAC__bwtemp;
* next one.
*/
static const uint32_t FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
/* When growing, increment 4K at a time */
static const uint32_t FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
/* When growing, increment with 1/4th at a time */
static const uint32_t FLAC__BITWRITER_DEFAULT_GROW_FRACTION = 2; /* means grow by >> 2 (1/4th) of current size */

#define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
#define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
Expand Down Expand Up @@ -131,11 +131,11 @@ FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, uint32_t bits_to_add)
* To prevent chrashing, give up */
return false;

/* round up capacity increase to the nearest FLAC__BITWRITER_DEFAULT_INCREMENT */
if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
/* As reallocation can be quite expensive, grow exponentially */
if((new_capacity - bw->capacity) < (bw->capacity >> FLAC__BITWRITER_DEFAULT_GROW_FRACTION))
new_capacity = bw->capacity + (bw->capacity >> FLAC__BITWRITER_DEFAULT_GROW_FRACTION);

/* make sure we got everything right */
FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
FLAC__ASSERT(new_capacity > bw->capacity);
FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));

Expand Down
19 changes: 15 additions & 4 deletions src/libFLAC/metadata_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,21 @@ FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_point
if (!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
return false;

for (j = 0; j < num; i++, j++) {
seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num;
seek_table->points[i].stream_offset = 0;
seek_table->points[i].frame_samples = 0;
if(total_samples < UINT64_MAX / num) {
/* No risk of overflow */
for (j = 0; j < num; i++, j++) {
seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num;
seek_table->points[i].stream_offset = 0;
seek_table->points[i].frame_samples = 0;
}
}
else {
/* Less precise, but can handle total_samples near UINT64_MAX */
for (j = 0; j < num; i++, j++) {
seek_table->points[i].sample_number = total_samples / (FLAC__uint64)num * (FLAC__uint64)j;
seek_table->points[i].stream_offset = 0;
seek_table->points[i].frame_samples = 0;
}
}
}

Expand Down
Loading