Merge "Fixes the crash issues caused by exif corruption in jhead." am: e7dac1df82
am: dd71aecc72

* commit 'dd71aecc726f9d8b5534d0902406d41bfaa487b8':
  Fixes the crash issues caused by exif corruption in jhead.

Change-Id: Ic45a855d8f2c03c9ee2361da8640a553cd720c41
diff --git a/README.version b/README.version
new file mode 100644
index 0000000..4779cb9
--- /dev/null
+++ b/README.version
@@ -0,0 +1,3 @@
+URL: http://www.sentex.net/~mwandel/jhead/jhead-2.87.tar.gz
+Version: 2.87
+BugComponent: 43059
diff --git a/exif.c b/exif.c
index f6d3536..561852b 100644
--- a/exif.c
+++ b/exif.c
@@ -1125,7 +1125,7 @@
 //--------------------------------------------------------------------------
 void process_EXIF (unsigned char * ExifSection, unsigned int length)
 {
-    int FirstOffset;
+    unsigned FirstOffset;
 
     FocalplaneXRes = 0;
     FocalplaneUnits = 0;
@@ -1164,9 +1164,8 @@
     }
 
     FirstOffset = Get32u(ExifSection+12);
-    if (FirstOffset < 8 || FirstOffset > 16){
-        // Usually set to 8, but other values valid too.
-        ErrNonfatal("Suspicious offset of first IFD value",0,0);
+    if (FirstOffset < 8 || FirstOffset+8 >= length) {
+        ErrNonfatal("Invalid offset of first IFD value: %u", FirstOffset, 0);
         return;
     }
 
@@ -1792,7 +1791,7 @@
 
     if (ImageInfo.DigitalZoomRatio > 1){
         // Digital zoom used.  Shame on you!
-        printf("Digital Zoom : %1.3fx\n", (double)ImageInfo.DigitalZoomRatio);
+        printf("Digital Zoom : %5.3fx\n", (double)ImageInfo.DigitalZoomRatio);
     }
 
     if (ImageInfo.CCDWidth){
@@ -1811,7 +1810,7 @@
         printf("\n");
     }
     if (ImageInfo.ApertureFNumber){
-        printf("Aperture     : f/%3.3f\n",(double)ImageInfo.ApertureFNumber);
+        printf("Aperture     : f/%5.3f\n",(double)ImageInfo.ApertureFNumber);
     }
     if (ImageInfo.Distance){
         if (ImageInfo.Distance < 0){
@@ -2004,7 +2003,7 @@
         if (ImageInfo.ExposureTime <= 0.5){
             printf(" (1/%d)",(int)(0.5 + 1/ImageInfo.ExposureTime));
         }else{
-            printf(" (%1.1f)",ImageInfo.ExposureTime);
+            printf(" (%3.1f)",ImageInfo.ExposureTime);
         }
     }
 
diff --git a/gpsinfo.c b/gpsinfo.c
index cbf261e..ba2e82a 100644
--- a/gpsinfo.c
+++ b/gpsinfo.c
@@ -257,7 +257,7 @@
 
             case TAG_GPS_TIMESTAMP:
                 snprintf(ImageInfo.GpsTimeStamp,
-                    sizeof(ImageInfo.GpsTimeStamp), "%d:%d:%d",
+                    sizeof(ImageInfo.GpsTimeStamp), "%02d:%02d:%02d",
                     (int) ConvertAnyFormat(ValuePtr, Format),
                     (int) ConvertAnyFormat(ValuePtr + 8, Format),
                     (int) ConvertAnyFormat(ValuePtr + 16, Format)
diff --git a/jpgfile.c b/jpgfile.c
index 214c888..8cc8125 100755
--- a/jpgfile.c
+++ b/jpgfile.c
@@ -816,7 +816,7 @@
     }
 
     int writeOk = FALSE;
-    int nWrite = 0;
+    size_t nWrite = 0;
     // Write all the misc sections
     for (a=0;a<SectionsRead-1;a++){
         fputc(0xff,outfile);
diff --git a/main.c b/main.c
index da45c1b..96c48bc 100644
--- a/main.c
+++ b/main.c
@@ -641,7 +641,7 @@
 
     if (ImageInfo.DigitalZoomRatio > 1.0){
         // Digital zoom used.  Shame on you!
-        bufLen = addKeyValueDouble(&buf, bufLen, "DigitalZoomRatio", ImageInfo.DigitalZoomRatio, "%1.3f");
+        bufLen = addKeyValueDouble(&buf, bufLen, "DigitalZoomRatio", ImageInfo.DigitalZoomRatio, "%5.3f");
         if (bufLen == 0) return NULL;
     }
 
@@ -658,7 +658,7 @@
     }
 
     if (ImageInfo.ApertureFNumber){
-        bufLen = addKeyValueDouble(&buf, bufLen, "FNumber", (double)ImageInfo.ApertureFNumber, "%3.3f");
+        bufLen = addKeyValueDouble(&buf, bufLen, "FNumber", (double)ImageInfo.ApertureFNumber, "%5.3f");
         if (bufLen == 0) return NULL;
     }