static bool ad_entry_check_size(uint32_t eid,
				size_t bufsize,
				uint32_t off,
				uint32_t got_len)
{
	struct {
		off_t expected_len;
		bool fixed_size;
		bool minimum_size;
	} ad_checks[] = {
		[ADEID_DFORK] = {-1, false, false}, /* not applicable */
		[ADEID_RFORK] = {-1, false, false}, /* no limit */
		[ADEID_NAME] = {ADEDLEN_NAME, false, false},
		[ADEID_COMMENT] = {ADEDLEN_COMMENT, false, false},
		[ADEID_ICONBW] = {ADEDLEN_ICONBW, true, false},
		[ADEID_ICONCOL] = {ADEDLEN_ICONCOL, false, false},
		[ADEID_FILEI] = {ADEDLEN_FILEI, true, false},
		[ADEID_FILEDATESI] = {ADEDLEN_FILEDATESI, true, false},
		[ADEID_FINDERI] = {ADEDLEN_FINDERI, false, true},
		[ADEID_MACFILEI] = {ADEDLEN_MACFILEI, true, false},
		[ADEID_PRODOSFILEI] = {ADEDLEN_PRODOSFILEI, true, false},
		[ADEID_MSDOSFILEI] = {ADEDLEN_MSDOSFILEI, true, false},
		[ADEID_SHORTNAME] = {ADEDLEN_SHORTNAME, false, false},
		[ADEID_AFPFILEI] = {ADEDLEN_AFPFILEI, true, false},
		[ADEID_DID] = {ADEDLEN_DID, true, false},
		[ADEID_PRIVDEV] = {ADEDLEN_PRIVDEV, true, false},
		[ADEID_PRIVINO] = {ADEDLEN_PRIVINO, true, false},
		[ADEID_PRIVSYN] = {ADEDLEN_PRIVSYN, true, false},
		[ADEID_PRIVID] = {ADEDLEN_PRIVID, true, false},
	};

	if (eid >= ADEID_MAX) {
		return false;
	}
	if (got_len == 0) {
		/* Entry present, but empty, allow */
		return true;
	}
	if (ad_checks[eid].expected_len == 0) {
		/*
		 * Shouldn't happen: implicitly initialized to zero because
		 * explicit initializer missing.
		 */
		return false;
	}
	if (ad_checks[eid].expected_len == -1) {
		/* Unused or no limit */
		return true;
	}
	if (ad_checks[eid].fixed_size) {
		if (ad_checks[eid].expected_len != got_len) {
			/* Wrong size fo fixed size entry. */
			return false;
		}
	} else {
		if (ad_checks[eid].minimum_size) {
			if (got_len < ad_checks[eid].expected_len) {
				/*
				 * Too small for variable sized entry with
				 * minimum size.
				 */
				return false;
			}
		} else {
			if (got_len > ad_checks[eid].expected_len) {
				/* Too big for variable sized entry. */
				return false;
			}
		}
	}
	if (off + got_len < off) {
		/* wrap around */
		return false;
	}
	if (off + got_len > bufsize) {
		/* overflow */
		return false;
	}
	return true;
}
static bool ad_entry_check_size(uint32_t eid,
				size_t bufsize,
				uint32_t off,
				uint32_t got_len)
{
	struct {
		off_t expected_len;
		bool fixed_size;
		bool minimum_size;
	} ad_checks[] = {
		[ADEID_DFORK] = {-1, false, false},  
		[ADEID_RFORK] = {-1, false, false},  
		[ADEID_NAME] = {ADEDLEN_NAME, false, false},
		[ADEID_COMMENT] = {ADEDLEN_COMMENT, false, false},
		[ADEID_ICONBW] = {ADEDLEN_ICONBW, true, false},
		[ADEID_ICONCOL] = {ADEDLEN_ICONCOL, false, false},
		[ADEID_FILEI] = {ADEDLEN_FILEI, true, false},
		[ADEID_FILEDATESI] = {ADEDLEN_FILEDATESI, true, false},
		[ADEID_FINDERI] = {ADEDLEN_FINDERI, false, true},
		[ADEID_MACFILEI] = {ADEDLEN_MACFILEI, true, false},
		[ADEID_PRODOSFILEI] = {ADEDLEN_PRODOSFILEI, true, false},
		[ADEID_MSDOSFILEI] = {ADEDLEN_MSDOSFILEI, true, false},
		[ADEID_SHORTNAME] = {ADEDLEN_SHORTNAME, false, false},
		[ADEID_AFPFILEI] = {ADEDLEN_AFPFILEI, true, false},
		[ADEID_DID] = {ADEDLEN_DID, true, false},
		[ADEID_PRIVDEV] = {ADEDLEN_PRIVDEV, true, false},
		[ADEID_PRIVINO] = {ADEDLEN_PRIVINO, true, false},
		[ADEID_PRIVSYN] = {ADEDLEN_PRIVSYN, true, false},
		[ADEID_PRIVID] = {ADEDLEN_PRIVID, true, false},
	};

	if (eid >= ADEID_MAX) {
		return false;
	}
	if (got_len == 0) {
		 
		return true;
	}
	if (ad_checks[eid].expected_len == 0) {
		 
		return false;
	}
	if (ad_checks[eid].expected_len == -1) {
		 
		return true;
	}
	if (ad_checks[eid].fixed_size) {
		if (ad_checks[eid].expected_len != got_len) {
			 
			return false;
		}
	} else {
		if (ad_checks[eid].minimum_size) {
			if (got_len < ad_checks[eid].expected_len) {
				 
				return false;
			}
		} else {
			if (got_len > ad_checks[eid].expected_len) {
				 
				return false;
			}
		}
	}
	if (off + got_len < off) {
		 
		return false;
	}
	if (off + got_len > bufsize) {
		 
		return false;
	}
	return true;
}