From 9aac670eeaed0cf4930253f7b1f6648775153bfe Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Wed, 8 Sep 2004 00:50:21 +0000 Subject: [PATCH] fix bug: source file needs to be explicitly rewound before reading/writing in callback mode --- src/libFLAC/metadata_iterators.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c index 9c56879f..45e5c3fe 100644 --- a/src/libFLAC/metadata_iterators.c +++ b/src/libFLAC/metadata_iterators.c @@ -1266,6 +1266,7 @@ static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *t return true; } +/* assumes 'handle' is already at beginning of file */ static FLAC__bool chain_rewrite_file_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb) { FLAC__Metadata_SimpleIteratorStatus status; @@ -1376,6 +1377,12 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chai return false; } + /* rewind */ + if(0 != callbacks.seek(handle, 0, SEEK_SET)) { + chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; + return false; + } + if(!chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell)) return false; /* chain->status is already set by chain_read_cb_ */ @@ -1527,6 +1534,12 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC_ FLAC__ASSERT(current_length != chain->initial_length); + /* rewind */ + if(0 != callbacks.seek(handle, 0, SEEK_SET)) { + chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; + return false; + } + if(!chain_rewrite_file_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.eof, temp_handle, temp_callbacks.write)) return false;