Fix possible out of bounds accesses am: ee54e6ceb6 am: 4c7c4297b5 am: 364ccf5071 am: fb76bf3245 am: 1a484d2270 am: d98576d450 am: de4cdf8758 am: d3d573ee65 am: f3d69fbae8 am: edad75e21a am: 1583b768ef
am: 0f569b3fbd

Change-Id: I6f8624489cde8e35185d11d4e6381665deb25513
diff --git a/gpsinfo.c b/gpsinfo.c
index ba2e82a..141cfc5 100644
--- a/gpsinfo.c
+++ b/gpsinfo.c
@@ -174,7 +174,7 @@
             unsigned OffsetVal;
             OffsetVal = Get32u(DirEntry+8);
             // If its bigger than 4 bytes, the dir entry contains an offset.
-            if (OffsetVal+ByteCount > ExifLength){
+            if (OffsetVal > UINT32_MAX - ByteCount || OffsetVal+ByteCount > ExifLength){
                 // Bogus pointer offset and / or bytecount value
                 ErrNonfatal("Illegal value pointer for tag %04x", Tag,0);
                 continue;
diff --git a/makernote.c b/makernote.c
index cf40c6b..514518d 100644
--- a/makernote.c
+++ b/makernote.c
@@ -62,7 +62,7 @@
             unsigned OffsetVal;
             OffsetVal = Get32u(DirEntry+8);
             // If its bigger than 4 bytes, the dir entry contains an offset.
-            if (OffsetVal+ByteCount > ExifLength){
+            if (OffsetVal > UINT32_MAX - ByteCount || OffsetVal+ByteCount > ExifLength){
                 // Bogus pointer offset and / or bytecount value
                 ErrNonfatal("Illegal value pointer for tag %04x", Tag,0);
                 continue;