Don't mix strlen() and ZSTR_LEN(). If the encoding contains a NULL byte, this will overflow the buffer. NULL bytes will still make this behave oddly because the consuming code will cut off the string there, but let's address that in master...
We must not assume that `hash_entry` `IS_STRING`, but rather use `encoding_str` which is guaranteed to be.