From 38162d5a651c4475cd9c550f19bb944615ee4845 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Sat, 16 Nov 2002 06:31:54 +0000 Subject: [PATCH] add more reserved space to CUESHEET implementation --- include/FLAC/format.h | 2 ++ src/libFLAC/format.c | 1 + src/libFLAC/metadata_iterators.c | 18 +++++++++++++++--- src/libFLAC/stream_decoder.c | 3 +++ src/libFLAC/stream_encoder_framing.c | 2 ++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/FLAC/format.h b/include/FLAC/format.h index 4b4a68dc..1f97c04d 100644 --- a/include/FLAC/format.h +++ b/include/FLAC/format.h @@ -663,7 +663,9 @@ typedef struct { extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */ extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */ +extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == @@@@256*8 (bits) */ extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */ +/*@@@@@ RESERVED SPACE HERE*/ /** FLAC metadata block structure. (c.f. format specification) diff --git a/src/libFLAC/format.c b/src/libFLAC/format.c index 53afb3fe..81d00e72 100644 --- a/src/libFLAC/format.c +++ b/src/libFLAC/format.c @@ -81,6 +81,7 @@ FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8 FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */ FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */ +FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 256*8; /* bits @@@@256 */ FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */ FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */ diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c index 8466a91e..618e3baa 100644 --- a/src/libFLAC/metadata_iterators.c +++ b/src/libFLAC/metadata_iterators.c @@ -1521,7 +1521,7 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_(FIL if(block->num_comments == 0) { block->comments = 0; } - else if(0 == (block->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)calloc(sizeof(FLAC__StreamMetadata_VorbisComment_Entry), block->num_comments))) + else if(0 == (block->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)calloc(block->num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR; for(i = 0; i < block->num_comments; i++) { @@ -1607,7 +1607,7 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_(FILE *fil { unsigned i, len; FLAC__Metadata_SimpleIteratorStatus status; - FLAC__byte buffer[sizeof(FLAC__uint64)]; /* the largest object we'll read in one shot */ + FLAC__byte buffer[max(sizeof(FLAC__uint64), FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN/8)]; /* the largest object we'll read in one shot */ FLAC__ASSERT(0 != file); @@ -1622,6 +1622,11 @@ FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_(FILE *fil return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; block->lead_in = unpack_uint64_(buffer, len); + FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN % 8 == 0); + len = FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN / 8; + if(fread(buffer, 1, len, file) != len) + return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR; + FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0); len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8; if(fread(buffer, 1, len, file) != len) @@ -1814,9 +1819,10 @@ FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_vorbis_comment_(FI FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_cuesheet_(FILE *file, const FLAC__StreamMetadata_CueSheet *block) { unsigned i, j, len; - FLAC__byte buffer[32]; /* asserted below that this is big enough */ + FLAC__byte buffer[1024]; /* asserted below that this is big enough */ FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64)); + FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN/8); FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)/8); FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8); @@ -1833,6 +1839,12 @@ FLAC__Metadata_SimpleIteratorStatus write_metadata_block_data_cuesheet_(FILE *fi if(fwrite(buffer, 1, len, file) != len) return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; + FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN % 8 == 0); + len = FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN / 8; + memset(buffer, 0, len); + if(fwrite(buffer, 1, len, file) != len) + return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR; + FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0); len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8; pack_uint32_(block->num_tracks, buffer, len); diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 3651a2d2..0071eba7 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -1128,6 +1128,9 @@ FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMet if(!FLAC__bitbuffer_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN, read_callback_, decoder)) return false; /* the read_callback_ sets the state for us */ + if(!FLAC__bitbuffer_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN, read_callback_, decoder)) + return false; /* the read_callback_ sets the state for us */ + if(!FLAC__bitbuffer_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN, read_callback_, decoder)) return false; /* the read_callback_ sets the state for us */ obj->num_tracks = x; diff --git a/src/libFLAC/stream_encoder_framing.c b/src/libFLAC/stream_encoder_framing.c index 3d4cf277..e0afb6a8 100644 --- a/src/libFLAC/stream_encoder_framing.c +++ b/src/libFLAC/stream_encoder_framing.c @@ -125,6 +125,8 @@ FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__ return false; if(!FLAC__bitbuffer_write_raw_uint64(bb, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN)) return false; + if(!FLAC__bitbuffer_write_zeroes(bb, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN)) + return false; if(!FLAC__bitbuffer_write_raw_uint32(bb, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN)) return false; for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) { -- 2.34.1