fix bug: source file needs to be explicitly rewound before reading/writing in callback mode
diff --git a/src/libFLAC/metadata_iterators.c b/src/libFLAC/metadata_iterators.c
index 9c56879..45e5c3f 100644
--- a/src/libFLAC/metadata_iterators.c
+++ b/src/libFLAC/metadata_iterators.c
@@ -1266,6 +1266,7 @@
 	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 @@
 		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__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;