Repository navigation
SEC require a TypeNode per entry in dict key types - #570
adrinjalali wants to merge 4 commits into
Conversation
DictNode calls each key type on its key when the dict is built, so the key type list must hold only types, one per entry. Check this while the file is read, for the current reader and the protocol <= 2 reader. Also stop saving the key type of a dict entry whose value is a property, which paired the remaining key types with the wrong keys on load.
|
@3urek4 would you mind having a look here as well? |
3urek4
left a comment
There was a problem hiding this comment.
Looks good to me overall, nice catch on skipping the property key type and mirroring the check to _general_v2.py.
One small thing I noticed around TypeNode in DictNode._construct (non-blocking, could also be a follow-up): builtin_function_or_method also dispatches to TypeNode, and TypeNode._construct just calls _import_obj(module_name, class_name) without checking that the result is a type. So if a caller trusts a 1-arg function (for example for a FunctionTransformer, where FunctionNode only imports the function on load without calling it), a crafted dict can put a TypeNode naming that function in key_types, pass both isinstance(key_type, TypeNode) and the audit, and have k_type(key) call it on a file-chosen string during loads(). Checking isinstance(k_type, type) in DictNode._construct (current and v2) would close that since dict_get_state always records type(key).
…r types Check the constructed key types before any is called, in the current and protocol <= 2 readers, through shared helpers. Refuse dicts whose keys collide as JSON keys at dump, give a ValueError for key types aliased to a list still being loaded, and drop the get_tree overloads.
Reference Issues/PRs
Follow-up to #547 (#222).
What does this implement/fix? Explain your changes.
DictNode._constructcalls each entry of the key-type list on its key. #547 only made sure the list itself is aListNode, which accepts any node as an entry, so a file could put a callable such as afunctools.partialthere and have it called with a string from the file while the dict is built. This requires every entry to be aTypeNode, and the number of key types to equal the number of entries (zipsilently truncated otherwise), in the current reader and in the protocol <= 2 reader inskops.io.old, which overrides__init__and would otherwise skip the check.On the save side, a dict entry whose value is a
propertyis skipped, but its key type was still recorded, which paired the remaining key types with the wrong keys on load. Key types are now recorded per saved entry.Any other comments?
The changelog amends the existing #547 entry.