summaryrefslogtreecommitdiff
path: root/third_party/libtiff/0013-validate-refblackwhite.patch
blob: a314fbdc3f1bb09b7dc821acd2e376932ad499bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/third_party/libtiff/tif_dir.c b/third_party/libtiff/tif_dir.c
index 73212c02d..16ce3d3ce 100644
--- a/third_party/libtiff/tif_dir.c
+++ b/third_party/libtiff/tif_dir.c
@@ -426,6 +426,14 @@ _TIFFVSetField(TIFF* tif, uint32 tag, va_list ap)
 	case TIFFTAG_REFERENCEBLACKWHITE:
 		/* XXX should check for null range */
 		_TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
+		for (int i = 0; i < 6; i++) {
+			if (isnan(td->td_refblackwhite[i])) {
+				if (i % 2 == 0)
+					td->td_refblackwhite[i] = 0;
+				else
+					td->td_refblackwhite[i] = pow(2, td->td_bitspersample) - 1;
+			}
+		}
 		break;
 	case TIFFTAG_INKNAMES:
 		v = (uint16) va_arg(ap, uint16_vap);