diff --git a/src/iproto.cc b/src/iproto.cc
index 8f0802492eecaabb57ad860f75fbc2c85fd26461..8771d8681618352ee9c50d0657a8b63c5ad1e6b4 100644
--- a/src/iproto.cc
+++ b/src/iproto.cc
@@ -477,9 +477,10 @@ iproto_enqueue_batch(struct iproto_connection *con, struct ibuf *in)
 			break;
 		uint32_t len = mp_decode_uint(&pos);
 		/* Skip optional request padding. */
-		if (mp_typeof(*pos) == MP_STR && mp_check(&pos, in->end))
+		if (pos < in->end && mp_typeof(*pos) == MP_STR &&
+		    mp_check(&pos, in->end)) {
 			goto error;
-
+		}
 		const char *reqend = pos + len;
 		if (reqend > in->end)
 			break;