Oops, good catch on the sub-array size check. And yeah, added the assertion that size_shift be zero; although I'm not sure whether I should be UTF-8 encoding (which may apply even if size_shift is nonzero) or handling non-ASCII strings in some other way.
IIUC the target is supposed to be a MIME-type, which means that non-ASCII is simply not allowed. So you could check the min and max of the string to make sure it only contains ASCII and no control characters (such as NUL).