Update of /cvsroot/libexif/libexif/libexif/olympus
In directory vz-cvs-4.sog:/tmp/cvs-serv19584/libexif/olympus

Modified Files:
	mnote-olympus-entry.c 
Log Message:
Fixed some possible division-by-zeros in Olympus-style makernotes
This fixes bug #3434545, a.k.a. CVE-2012-2837


Index: libexif/olympus/mnote-olympus-entry.c
===================================================================
--- libexif/olympus/mnote-olympus-entry.c.orig
+++ libexif/olympus/mnote-olympus-entry.c
@@ -76,6 +76,9 @@
 	}                                                               \
 }
 
+#define R2L(n) ((n).denominator ? (long)(n).numerator/(n).denominator : 0L)
+#define R2D(n) ((n).denominator ? (double)(n).numerator/(n).denominator : 0.0)
+
 static const struct {
 	ExifTag tag;
     ExifFormat fmt;
@@ -345,9 +348,9 @@ mnote_olympus_entry_get_value (MnoteOlym
 		CF (entry->format, EXIF_FORMAT_RATIONAL, v, maxlen);
 		CC (entry->components, 4, v, maxlen);
 		vr = exif_get_rational (entry->data, entry->order);
-		r = (double)vr.numerator / vr.denominator;
+		r = R2D(vr);
 		vr = exif_get_rational (entry->data+8, entry->order);
-		b = (double)vr.numerator / vr.denominator;
+		b = R2D(vr);
 		//printf("numerator %li, denominator %li\n", vr.numerator, vr.denominator);
 		snprintf (v, maxlen, _("Red Correction %f, Blue Correction %f"), r,b);
 		break;
@@ -355,8 +358,8 @@ mnote_olympus_entry_get_value (MnoteOlym
 		CF (entry->format, EXIF_FORMAT_RATIONAL, v, maxlen);
 		CC (entry->components, 1, v, maxlen);
 		vr = exif_get_rational (entry->data, entry->order);
-		if (vr.numerator) {
-			r = (double)vr.numerator / vr.denominator;
+		if (vr.numerator && vr.denominator) {
+			r = R2D(vr);
 			snprintf (v, maxlen, _("%2.2f meters"), r);
 		} else {
 			strncpy (v, _("No manual focus selection"), maxlen);
@@ -367,8 +370,8 @@ mnote_olympus_entry_get_value (MnoteOlym
 		CC (entry->components, 2, v, maxlen);
 		vr = exif_get_rational (entry->data, entry->order);
 		vr2 = exif_get_rational (entry->data+8, entry->order);
-		r = (double)vr.numerator / vr.denominator;
-		b = (double)vr2.numerator / vr2.denominator;
+		r = R2D(vr);
+		b = R2D(vr2);
 		snprintf (v, maxlen, "%2.2f x %2.2f um", r, b);
 		break;
 	case MNOTE_NIKON_TAG_BRACKETING:
@@ -424,10 +427,10 @@ mnote_olympus_entry_get_value (MnoteOlym
 		if (entry->format == EXIF_FORMAT_RATIONAL) {
 			CC (entry->components, 1, v, maxlen);
 			vr = exif_get_rational (entry->data, entry->order);
-			r = (double)vr.numerator / vr.denominator;
-			if (!vr.numerator) {
+			if (!vr.numerator || !vr.denominator) {
 				strncpy (v, _("None"), maxlen);
 			} else {
+				r = R2D(vr);
 				snprintf (v, maxlen, "%2.2f", r);
 			}
 			break;
@@ -520,13 +523,13 @@ mnote_olympus_entry_get_value (MnoteOlym
 			double c,d;
 			unsigned long a,b;
 			vr = exif_get_rational (entry->data, entry->order);
-			a = vr.numerator / vr.denominator;
+			a = R2L(vr);
 			vr = exif_get_rational (entry->data+8, entry->order);
-			b = vr.numerator / vr.denominator;
+			b = R2L(vr);
 			vr = exif_get_rational (entry->data+16, entry->order);
-			c = (double)vr.numerator / vr.denominator;
+			c = R2D(vr);
 			vr = exif_get_rational (entry->data+24, entry->order);
-			d = (double)vr.numerator / vr.denominator;
+			d = R2D(vr);
                         //printf("numerator %li, denominator %li\n", vr.numerator, vr.denominator);
 			snprintf (v, maxlen, "%ld-%ldmm 1:%3.1f - %3.1f",a,b,c,d);
 		}
@@ -622,11 +625,11 @@ mnote_olympus_entry_get_value (MnoteOlym
 		CF (entry->format, EXIF_FORMAT_RATIONAL, v, maxlen);
 		CC (entry->components, 1, v, maxlen);
 		vr = exif_get_rational (entry->data, entry->order);
-		if (vr.numerator == 0) {
+		if (!vr.numerator || !vr.denominator) {
 			strncpy (v, _("Unknown"), maxlen);
 		}
 		else {
-			unsigned long tmp = vr.numerator / vr.denominator;
+			unsigned long tmp = R2L(vr);
 			/* printf("numerator %li, denominator %li\n", vr.numerator, vr.denominator); */
 			snprintf (v, maxlen, "%li mm", tmp);
 		}
@@ -734,7 +737,7 @@ mnote_olympus_entry_get_value (MnoteOlym
 			if (!vr.denominator) {
 				strncpy (v, _("Infinite"), maxlen);
 			} else {
-				r = (double)vr.numerator / vr.denominator;
+				r = R2D(vr);
 				snprintf (v, maxlen, "%2.3f", r);
 			}
 			break;
@@ -744,7 +747,7 @@ mnote_olympus_entry_get_value (MnoteOlym
 			if (!vsr.denominator) {
 				strncpy (v, _("Infinite"), maxlen);
 			} else {
-				r = (double)vsr.numerator / vsr.denominator;
+				r = R2D(vsr);
 				snprintf (v, maxlen, "%2.3f", r);
 			}
 			break;
