diff --git a/doc/html/changelog.html b/doc/html/changelog.html
index 44b7f49f..e899aa4c 100644
--- a/doc/html/changelog.html
+++ b/doc/html/changelog.html
@@ -105,6 +105,7 @@
MD5 comparison failures on decoding are now an error instead of a warning and will also return a non-zero exit code (SF #1493725).
The default padding size is now 8K, or 64K if the input audio stream is more than 20 minutes long.
Fixed a bug in cuesheet parsing where it would return an error if the last line of the cuesheet did not end with a newline.
+ Fixed a bug where missing STREAMINFO fields (min/max framesize, total samples, MD5 sum) and seek point offsets were not getting rewritten back to Ogg FLAC file (SF #1338969).
Fixed a bug that caused a crash when -a and -t were used together (SF #1229481).
Fixed a bug with --sector-align where appended samples were not always totally silent (SF #1237707).
Fixed bugs with --sector-align and raw input files.
diff --git a/doc/html/documentation.html b/doc/html/documentation.html
index 99952abd..d752541d 100644
--- a/doc/html/documentation.html
+++ b/doc/html/documentation.html
@@ -1443,7 +1443,7 @@
The following are major known bugs in the current (1.1.3) release:
-
- (none)
+ When encoding to Ogg FLAC, if there are too many seek points (>240), the seek table will not have the offsets written back properly after encoding.
The following are major known bugs in the 1.1.0 release:
diff --git a/src/libFLAC/ogg_helper.c b/src/libFLAC/ogg_helper.c
index 80f7528d..d368fca7 100644
--- a/src/libFLAC/ogg_helper.c
+++ b/src/libFLAC/ogg_helper.c
@@ -150,7 +150,7 @@ FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
}
}
- page->body_len = 255 * i + page->header[i];
+ page->body_len = 255 * i + page->header[i + OGG_HEADER_FIXED_PORTION_LEN];
}
/* allocate space for the page body */
@@ -199,6 +199,10 @@ FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 po
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
}
+ if(write_callback((FLAC__StreamEncoder*)encoder, page->body, page->body_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
+ encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
+ return false;
+ }
return true;
}
diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c
index 65ec3e2a..ec6a0f59 100644
--- a/src/libFLAC/stream_encoder.c
+++ b/src/libFLAC/stream_encoder.c
@@ -66,6 +66,7 @@
#include "private/memory.h"
#ifdef FLAC__HAS_OGG
#include "private/ogg_helper.h"
+#include "private/ogg_mapping.h"
#endif
#include "private/stream_encoder_framing.h"
#include "private/window.h"
@@ -2895,6 +2896,15 @@ void update_metadata_(const FLAC__StreamEncoder *encoder)
/* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */
void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
{
+ /* the # of bytes in the 1st packet that precede the STREAMINFO */
+ static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
+ FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
+ FLAC__OGG_MAPPING_MAGIC_LENGTH +
+ FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
+ FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
+ FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
+ FLAC__STREAM_SYNC_LENGTH
+ ;
FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
@@ -2923,6 +2933,7 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
*/
{
const unsigned md5_offset =
+ FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
@@ -2948,6 +2959,7 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
*/
{
const unsigned total_samples_byte_offset =
+ FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
@@ -2979,6 +2991,7 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
*/
{
const unsigned min_framesize_offset =
+ FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
@@ -3021,7 +3034,7 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
return; /* state already set */
}
- if(FLAC__STREAM_METADATA_HEADER_LENGTH + (18*encoder->private_->seek_table->num_points) > (unsigned)page.body_len) {
+ if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
@@ -3051,11 +3064,6 @@ void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
x = encoder->private_->seek_table->points[i].frame_samples;
b[17] = (FLAC__byte)x; x >>= 8;
b[16] = (FLAC__byte)x; x >>= 8;
- if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
- encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
- simple_ogg_page__clear(&page);
- return;
- }
memcpy(p, b, 18);
}