You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MAX_STRING_LEN is 128, so it's possible to construct a ContractName with up to 128 characters. However, when we implement StacksMessageCodec for ContractName:
CONTRACT_MAX_NAME_LENGTH is 40, much smaller than MAX_STRING_LEN. This means that ContractName::try_from() allows us to create structs that can't be serialized
Proposed solutions
Change the macro to use CONTRACT_MAX_NAME_LENGTH instead of MAX_STRING_LEN. This won't actually fix the problem, and will likely expose more invalid ContractNames that were never being serialized, but it will make invalid ContractNames easy to find and fix. Where it fails, we can replace ContractName::try_from() with ContractName::from_truncated() or ContractName::try_from_truncated()
Change CONTRACT_MAX_NAME_LENGTH to match MAX_STRING_LEN. Probably not what we want to do, but would fix the issue immediately
Description
The
ContractName
struct is implemented using a macro, like this:MAX_STRING_LEN
is 128, so it's possible to construct aContractName
with up to 128 characters. However, when we implementStacksMessageCodec
forContractName
:CONTRACT_MAX_NAME_LENGTH
is 40, much smaller thanMAX_STRING_LEN
. This means thatContractName::try_from()
allows us to create structs that can't be serializedProposed solutions
CONTRACT_MAX_NAME_LENGTH
instead ofMAX_STRING_LEN
. This won't actually fix the problem, and will likely expose more invalidContractName
s that were never being serialized, but it will make invalidContractName
s easy to find and fix. Where it fails, we can replaceContractName::try_from()
withContractName::from_truncated()
orContractName::try_from_truncated()
CONTRACT_MAX_NAME_LENGTH
to matchMAX_STRING_LEN
. Probably not what we want to do, but would fix the issue immediatelyRelated issues
The text was updated successfully, but these errors were encountered: