From 58b62adcc6663c292378d192dfcb7788fde6604e Mon Sep 17 00:00:00 2001 From: Martijn van Beurden Date: Mon, 14 Oct 2024 14:06:46 +0200 Subject: [PATCH] Convert unused seekpoints in template to placeholders See https://lists.xiph.org/pipermail/flac-dev/2024-October/006671.html for details --- src/libFLAC/stream_encoder.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c index f810b3c406..a10b5d84b0 100644 --- a/src/libFLAC/stream_encoder.c +++ b/src/libFLAC/stream_encoder.c @@ -3178,14 +3178,15 @@ void update_metadata_(const FLAC__StreamEncoder *encoder) FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN - 4 ) / 8; + FLAC__uint64 samples_uint36 = samples; if(samples > (FLAC__U64L(1) << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN)) - samples = 0; + samples_uint36 = 0; - b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F); - b[1] = (FLAC__byte)((samples >> 24) & 0xFF); - b[2] = (FLAC__byte)((samples >> 16) & 0xFF); - b[3] = (FLAC__byte)((samples >> 8) & 0xFF); - b[4] = (FLAC__byte)(samples & 0xFF); + b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples_uint36 >> 32) & 0x0F); + b[1] = (FLAC__byte)((samples_uint36 >> 24) & 0xFF); + b[2] = (FLAC__byte)((samples_uint36 >> 16) & 0xFF); + b[3] = (FLAC__byte)((samples_uint36 >> 8) & 0xFF); + b[4] = (FLAC__byte)(samples_uint36 & 0xFF); if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; @@ -3231,6 +3232,11 @@ void update_metadata_(const FLAC__StreamEncoder *encoder) if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) { uint32_t i; + /* Convert unused seekpoints to placeholders */ + for(i = 0; i < encoder->private_->seek_table->num_points; i++) + if(encoder->private_->seek_table->points[i].sample_number > samples) + encoder->private_->seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER; + FLAC__format_seektable_sort(encoder->private_->seek_table); FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));