Skip to content

Commit

Permalink
Add two error statuses to the stream decoder for broken files (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmf01 authored Sep 29, 2024
1 parent d367d6f commit b8efde2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
14 changes: 13 additions & 1 deletion include/FLAC/stream_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,21 @@ typedef enum {
FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM,
/**< The decoder encountered reserved fields in use in the stream. */

FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA
FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA,
/**< The decoder encountered a corrupted metadata block. */

FLAC__STREAM_DECODER_ERROR_STATUS_OUT_OF_BOUNDS,
/**< The decoder encountered a otherwise valid frame in which
* the decoded samples exceeded the range offered by the stated
* bit depth. */

FLAC__STREAM_DECODER_ERROR_STATUS_MISSING_FRAME
/**< Two adjacent frames had frame numbers increasing by more than
* 1 or sample numbers increasing by more than the blocksize,
* indicating that one or more frame/frames was missing between
* them. The decoder will sent out one or more ´fake' constant
* subframes to fill up the gap. */

} FLAC__StreamDecoderErrorStatus;

/** Maps a FLAC__StreamDecoderErrorStatus to a C string.
Expand Down
8 changes: 5 additions & 3 deletions src/libFLAC/stream_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
"FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
"FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
"FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM",
"FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA"
"FLAC__STREAM_DECODER_ERROR_STATUS_BAD_METADATA",
"FLAC__STREAM_DECODER_ERROR_STATUS_OUT_OF_BOUNDS",
"FLAC__STREAM_DECODER_ERROR_STATUS_MISSING_FRAME"
};

/***********************************************************************
Expand Down Expand Up @@ -2282,7 +2284,7 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
if((decoder->private_->output[channel][i] < (INT32_MIN >> shift_bits)) ||
(decoder->private_->output[channel][i] > (INT32_MAX >> shift_bits))) {
/* Bad frame, emit error */
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_OUT_OF_BOUNDS);
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
break;
}
Expand All @@ -2309,7 +2311,7 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
* frames are missing, and the frames before and after it
* are complete */
if(!decoder->private_->error_has_been_sent)
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_MISSING_FRAME);
/* Do some extra validation to assure last frame an current frame
* header are both valid before adding silence inbetween
* Technically both frames could be valid with differing sample_rates,
Expand Down
Binary file modified test/abi/abi-libFLAC++-1.5.0.dump.xz
Binary file not shown.
Binary file modified test/abi/abi-libFLAC-1.5.0.dump.xz
Binary file not shown.

0 comments on commit b8efde2

Please sign in to comment.