Index: /libmpc/trunk/libmpcdec/internal.h
===================================================================
--- /libmpc/trunk/libmpcdec/internal.h	(revision 435)
+++ /libmpc/trunk/libmpcdec/internal.h	(revision 436)
@@ -84,4 +84,16 @@
 };
 
+/**
+ * checks if a block key is valid
+ * @param key the two caracters key to check
+ * @return MPC_STATUS_INVALIDSV if the key is invalid, MPC_STATUS_OK else
+ */
+static mpc_inline mpc_status mpc_check_key(char * key)
+{
+	if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90)
+		return MPC_STATUS_INVALIDSV;
+	return MPC_STATUS_OK;
+}
+
 /// helper functions used by multiple files
 mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
Index: /libmpc/trunk/libmpcdec/mpc_demux.c
===================================================================
--- /libmpc/trunk/libmpcdec/mpc_demux.c	(revision 435)
+++ /libmpc/trunk/libmpcdec/mpc_demux.c	(revision 436)
@@ -112,16 +112,4 @@
 
 	return (mpc_uint32_t) -1;
-}
-
-/**
- * checks if a block key is valid
- * @param key the two caracters key to check
- * @return MPC_STATUS_INVALIDSV if the key is invalid, MPC_STATUS_OK else
- */
-static mpc_inline mpc_status mpc_check_key(char * key)
-{
-	if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90)
-		return MPC_STATUS_INVALIDSV;
-	return MPC_STATUS_OK;
 }
 
Index: /libmpc/trunk/mpccut/mpccut.c
===================================================================
--- /libmpc/trunk/mpccut/mpccut.c	(revision 435)
+++ /libmpc/trunk/mpccut/mpccut.c	(revision 436)
@@ -165,4 +165,8 @@
 
 	while( memcmp(b.key, "AP", 2) != 0 ) {
+		if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
+			fprintf(stderr, "Error : invalid input stream\n");
+			goto error;
+		}
 		if (memcmp(b.key, "EI", 2) == 0)
 			copy_data(in_file, i, e.outputFile, b.size + size);
@@ -182,4 +186,8 @@
 
 	while( start_block != 0 ){
+		if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
+			fprintf(stderr, "Error : invalid input stream\n");
+			goto error;
+		}
 		if (memcmp(b.key, "AP", 2) == 0)
 			start_block--;
@@ -193,4 +201,8 @@
 
 	while( block_num != 0 ){
+		if ((err = mpc_check_key(b.key)) != MPC_STATUS_OK) {
+			fprintf(stderr, "Error : invalid input stream\n");
+			goto error;
+		}
 		if (memcmp(b.key, "AP", 2) == 0) {
 			if ((e.block_cnt & ((1 << e.seek_pwr) - 1)) == 0) {
@@ -214,4 +226,5 @@
 	writeBlock(&e, "SE", MPC_FALSE, 0); // write end of stream block
 
+error:
 	fclose ( e.outputFile );
 	fclose ( in_file );
@@ -219,4 +232,6 @@
 	mpc_reader_exit_stdio(&reader);
 	mpc_encoder_exit(&e);
+	if (err != MPC_STATUS_OK)
+		remove(argv[optind + 1]);
 
     return err;
