Fix analyze mode trying to get positions from stdin (#720)

Credit: Oss-Fuzz
Issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=68539
This commit is contained in:
Martijn van Beurden 2024-07-11 07:24:01 +02:00 committed by GitHub
parent 9977773a60
commit 15ea6ef822
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 7 deletions

View File

@ -62,7 +62,7 @@ void flac__analyze_init(analysis_options aopts)
}
}
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout)
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__bool decode_position_valid, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout)
{
const uint32_t channels = frame->header.channels;
char outfilename[1024];
@ -70,7 +70,10 @@ void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__
uint32_t i, channel, partitions;
/* do the human-readable part first */
fprintf(fout, "frame=%u\toffset=%" PRIu64 "\tbits=%" PRIu64 "\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
if(decode_position_valid)
fprintf(fout, "frame=%u\toffset=%" PRIu64 "\tbits=%" PRIu64 "\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame_offset, frame_bytes*8, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
else
fprintf(fout, "frame=%u\toffset=?\tbits=?\tblocksize=%u\tsample_rate=%u\tchannels=%u\tchannel_assignment=%s\n", frame_number, frame->header.blocksize, frame->header.sample_rate, channels, FLAC__ChannelAssignmentString[frame->header.channel_assignment]);
for(channel = 0; channel < channels; channel++) {
const FLAC__Subframe *subframe = frame->subframes+channel;
const FLAC__bool is_rice2 = subframe->data.fixed.entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;

View File

@ -26,7 +26,7 @@ typedef struct {
} analysis_options;
void flac__analyze_init(analysis_options aopts);
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout);
void flac__analyze_frame(const FLAC__Frame *frame, uint32_t frame_number, FLAC__bool decode_position_valid, FLAC__uint64 frame_offset, FLAC__uint64 frame_bytes, analysis_options aopts, FILE *fout);
void flac__analyze_finish(analysis_options aopts);
#endif

View File

@ -87,6 +87,7 @@ typedef struct {
/* these are used only in analyze mode */
FLAC__uint64 decode_position;
FLAC__bool decode_position_valid;
FLAC__StreamDecoder *decoder;
@ -249,6 +250,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
d->channel_mask = 0;
d->decode_position = 0;
d->decode_position_valid = true;
d->decoder = 0;
@ -401,7 +403,8 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
}
if(d->analysis_mode)
FLAC__stream_decoder_get_decode_position(d->decoder, &d->decode_position);
if(!FLAC__stream_decoder_get_decode_position(d->decoder, &d->decode_position))
d->decode_position_valid = false;
if(d->abort_flag)
return false;
@ -1231,9 +1234,10 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
}
}
if(decoder_session->analysis_mode) {
if(decoder_session->analysis_mode && decoder_session->decode_position_valid) {
FLAC__uint64 dpos;
FLAC__stream_decoder_get_decode_position(decoder_session->decoder, &dpos);
if(!FLAC__stream_decoder_get_decode_position(decoder_session->decoder, &dpos))
decoder_session->decode_position_valid = false;
frame_bytes = (dpos-decoder_session->decode_position);
decoder_session->decode_position = dpos;
}
@ -1280,7 +1284,7 @@ FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder
if(decoder_session->analysis_mode) {
flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position-frame_bytes, frame_bytes, decoder_session->aopts, fout);
flac__analyze_frame(frame, decoder_session->frame_counter-1, decoder_session->decode_position_valid, decoder_session->decode_position_valid?(decoder_session->decode_position-frame_bytes):0, frame_bytes, decoder_session->aopts, fout);
}
else if(!decoder_session->test_only) {
if(shift && !decoder_session->replaygain.apply) {