Skip to content

Commit

Permalink
Fix some more undefined behaviour
Browse files Browse the repository at this point in the history
As #784 notified me of
undefined behaviour going undetected by the fuzzers, I ran the test
suite with the full undefined behaviour sanitizer enabled.

There is one bit of undefined behaviour that I cannot fix,
FLAC__metadata_get_picture allows a picture type of -1 to mean all,
but this isn't part of the enum.
  • Loading branch information
ktmf01 committed Jan 21, 2025
1 parent a628cca commit e1f62eb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libFLAC/include/private/ogg_encoder_aspect.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect);
FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect);
void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect);

typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data);
typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data);

FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data);
#endif
3 changes: 2 additions & 1 deletion src/share/grabbag/cuesheet.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static FLAC__bool local__cuesheet_parse_(FILE *file, const char **error_message,
}
else if(0 == FLAC__STRCASECMP(field, "INDEX")) {
FLAC__int64 xx;
FLAC__StreamMetadata_CueSheet_Track *track = &cs->tracks[cs->num_tracks-1];
FLAC__StreamMetadata_CueSheet_Track *track;
if(in_track_num < 0) {
*error_message = "found INDEX before any TRACK";
return false;
Expand All @@ -347,6 +347,7 @@ static FLAC__bool local__cuesheet_parse_(FILE *file, const char **error_message,
return false;
}
FLAC__ASSERT(cs->num_tracks > 0);
track = &cs->tracks[cs->num_tracks-1];
if(track->num_indices == 0) {
/* it's the first index point of the track */
if(in_index_num > 1) {
Expand Down
6 changes: 3 additions & 3 deletions src/test_streams/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ static FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 x)
static FLAC__bool write_big_endian(FILE *f, FLAC__int32 x, size_t bytes)
{
if(bytes < 4)
x <<= 8*(4-bytes);
x = (uint32_t)x << 8*(4-bytes);
while(bytes) {
if(fputc(x>>24, f) == EOF)
return false;
x <<= 8;
x = (uint32_t)x << 8;
bytes--;
}
return true;
Expand Down Expand Up @@ -1057,7 +1057,7 @@ static FLAC__bool write_simple_wavex_header (FILE * f, unsigned samplerate, unsi
static FLAC__bool generate_noisy_sine(void)
{
FILE *f;
int64_t randstate = 0x1243456;
uint64_t randstate = 0x1243456;
double sample, last_val = 0.0;
int k;
int seconds = 300;
Expand Down

0 comments on commit e1f62eb

Please sign in to comment.