TIFFDirectory uses unsigned long which can be 32 or 64 bits
TIFFDirectory
’s td_fieldsset[]
field is unsigned long
which can be 32 or 64 bits.
It should be uint32_t
as it is only ever used as a 32-bit unsigned int.
Also, for what it’s worth, TIFFFreeDirectory()
only zeros td_fieldsset
’s first 4 bytes.
This small patch fixes both of these:
--- tif_dir.orig.h 2022-11-11 21:05:23.000000000 +0000
+++ tif_dir.h 2022-11-11 21:17:27.000000000 +0000
@@ -68,4 +68,2 @@
-#define FIELD_SETLONGS 4
- /* bit vector of fields that are set */
- unsigned long td_fieldsset[FIELD_SETLONGS];
-
+# define FIELDSET_ITEMS 4
+ uint32_t td_fieldsset[FIELDSET_ITEMS]; /* bit vector of fields that are set */
@@ -194 +192 @@
-#define FIELD_LAST (32*FIELD_SETLONGS-1)
+#define FIELD_LAST (32*FIELDSET_ITEMS-1)
@@ -196 +194 @@
-#define BITn(n) (((unsigned long)1L)<<((n)&0x1f))
+#define BITn(n) (((uint32_t)1)<<((n)&0x1f))
--- tif_dir.orig.c 2022-11-11 21:05:33.000000000 +0000
+++ tif_dir.c 2022-11-11 21:14:04.000000000 +0000
@@ -1423 +1423 @@
- _TIFFmemset(td->td_fieldsset, 0, FIELD_SETLONGS);
+ _TIFFmemset(td->td_fieldsset, 0, sizeof(td->td_fieldsset));