boot: add precise check of the image size

It is possible that image in the slot is so big
that MCUboot swap metadata will interfere with
its content during the swap operation.

This patch introduces additional check to the image
validation procedure.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c
index 6891394..e8a3cc2 100644
--- a/boot/bootutil/src/image_validate.c
+++ b/boot/bootutil/src/image_validate.c
@@ -376,6 +376,11 @@
         goto out;
     }
 
+    if (it.tlv_end > bootutil_max_image_size(fap)) {
+        rc = -1;
+        goto out;
+    }
+
     /*
      * Traverse through all of the TLVs, performing any checks we know
      * and are able to do.