Commit 1cb23412 authored by Josh Coalson's avatar Josh Coalson
Browse files

max the largest metadata type code be 126, reserving 127 to avoid confusion with a frame sync code

parent 5bf54f0a
...@@ -399,7 +399,10 @@ ...@@ -399,7 +399,10 @@
<TT>5</TT> : CUESHEET <TT>5</TT> : CUESHEET
</LI> </LI>
<LI> <LI>
<TT>6-127</TT> : reserved <TT>6-126</TT> : reserved
</LI>
<LI>
<TT>127</TT> : invalid, to avoid confusion with a frame sync code
</LI> </LI>
</UL> </UL>
</TD> </TD>
......
...@@ -88,6 +88,9 @@ extern "C" { ...@@ -88,6 +88,9 @@ extern "C" {
format specification. There is nothing to tune here. format specification. There is nothing to tune here.
*/ */
/** The largest legal metadata type code. */
#define FLAC__MAX_METADATA_TYPE_CODE (126u)
/** The minimum block size, in samples, permitted by the format. */ /** The minimum block size, in samples, permitted by the format. */
#define FLAC__MIN_BLOCK_SIZE (16u) #define FLAC__MIN_BLOCK_SIZE (16u)
......
...@@ -1084,7 +1084,8 @@ FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_It ...@@ -1084,7 +1084,8 @@ FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_It
* *
* \param type Type of object to create * \param type Type of object to create
* \retval FLAC__StreamMetadata* * \retval FLAC__StreamMetadata*
* \c NULL if there was an error allocating memory, else the new instance. * \c NULL if there was an error allocating memory or the type code is
* greater than FLAC__MAX_METADATA_TYPE_CODE, else the new instance.
*/ */
FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type); FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
......
...@@ -334,7 +334,12 @@ static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__Stream ...@@ -334,7 +334,12 @@ static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__Stream
FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type) FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type)
{ {
FLAC__StreamMetadata *object = (FLAC__StreamMetadata*)calloc(1, sizeof(FLAC__StreamMetadata)); FLAC__StreamMetadata *object;
if(type > FLAC__MAX_METADATA_TYPE_CODE)
return 0;
object = (FLAC__StreamMetadata*)calloc(1, sizeof(FLAC__StreamMetadata));
if(0 != object) { if(0 != object) {
object->is_last = false; object->is_last = false;
object->type = type; object->type = type;
......
...@@ -402,9 +402,9 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecode ...@@ -402,9 +402,9 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecode
FLAC__ASSERT(0 != decoder); FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_); FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_); FLAC__ASSERT(0 != decoder->protected_);
FLAC__ASSERT((unsigned)type < (1u << FLAC__STREAM_METADATA_TYPE_LEN)); FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
/* double protection */ /* double protection */
if((unsigned)type >= (1u << FLAC__STREAM_METADATA_TYPE_LEN)) if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
return false; return false;
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return false; return false;
...@@ -459,9 +459,9 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder ...@@ -459,9 +459,9 @@ FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder
FLAC__ASSERT(0 != decoder); FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_); FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_); FLAC__ASSERT(0 != decoder->protected_);
FLAC__ASSERT((unsigned)type < (1u << FLAC__STREAM_METADATA_TYPE_LEN)); FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
/* double protection */ /* double protection */
if((unsigned)type >= (1u << FLAC__STREAM_METADATA_TYPE_LEN)) if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
return false; return false;
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment