Index: /libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 272)
+++ /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 273)
@@ -364,5 +364,5 @@
 }
 
-void mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
+mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
 {
 	mpc_bits_reader r;
@@ -382,5 +382,5 @@
 				if (memcmp(b.key, "SE", 2) == 0) { // end block
 					i->bits = -1;
-					return;
+					return MPC_STATUS_OK;
 				}
 				mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0);
@@ -392,6 +392,6 @@
 			i->is_key_frame = MPC_TRUE;
 		}
-		// FIXME : this is not good if block size > buffer size
-		mpc_demux_fill(d, (d->block_bits >> 3) + 1, 0);
+		if (d->buffer + d->bytes_total - d->bits_reader.buff <= MAX_FRAME_SIZE)
+			mpc_demux_fill(d, (d->block_bits >> 3) + 1, 0);
 		r = d->bits_reader;
 		mpc_decoder_decode_frame(d->d, &d->bits_reader, i);
@@ -399,7 +399,6 @@
 		d->block_frames--;
 		if (d->block_bits < 0 || (d->block_frames == 0 && d->block_bits > 7)) {
-			// an error occured, stop decoding
-			// FIXME : return an error code.
 			i->bits = -1; // we pretend it's end of file
+			return MPC_STATUS_INVALIDSV;
 		}
 	} else {
@@ -413,14 +412,13 @@
 		mpc_decoder_decode_frame(d->d, &d->bits_reader, i);
 		if (d->block_bits != ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count) {
-			// an error occured, stop decoding
-			// FIXME : return an error code.
 			i->bits = -1; // we pretend it's end of file
+			return MPC_STATUS_INVALIDSV;
 		}
 	}
 	if (d->buffer + d->bytes_total < d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3)) {
-		// we're reading outside the buffer bytes, this is an error !
-		// FIXME : return an error code.
 		i->bits = -1; // we pretend it's end of file
-	}
+		return MPC_STATUS_INVALIDSV;
+	}
+	return MPC_STATUS_OK;
 }
 
