From 1e3fb451f380eead469059296f2b7878796c1af1 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 2 May 2009 16:15:46 +0000 Subject: [PATCH] Fixed the load_bmp function with respect to another weird BMP format I found. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403025 --- dlib/image_loader/image_loader.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dlib/image_loader/image_loader.h b/dlib/image_loader/image_loader.h index 91845886d..f79c7123d 100644 --- a/dlib/image_loader/image_loader.h +++ b/dlib/image_loader/image_loader.h @@ -12,6 +12,7 @@ #include "../entropy_decoder_model.h" #include "../entropy_decoder.h" #include "../uintn.h" +#include "../image_transforms/assign_image.h" #include namespace dlib @@ -412,7 +413,13 @@ namespace dlib // This is the escape code for a run of uncompressed bytes if (row < 0 || col + command > image.nc()) + { + // If this is just some padding bytes at the end then ignore them + if (row >= 0 && col + count <= image.nc() + padding) + continue; + throw image_load_error("bmp load error 21.2: file data corrupt"); + } // put the bytes into the image for (unsigned int i = 0; i < command; ++i) @@ -439,12 +446,20 @@ namespace dlib throw image_load_error("bmp load error 21.4: file too short"); } } + + continue; } rgb_pixel p; if (row < 0 || col + count > image.nc()) + { + // If this is just some padding bytes at the end then ignore them + if (row >= 0 && col + count <= image.nc() + padding) + continue; + throw image_load_error("bmp load error 21.5: file data corrupt"); + } // put the bytes into the image for (unsigned int i = 0; i < count; ++i)