Skip to content

namespace._copy trips on dict values that are types #126

@aaaaalbert

Description

@aaaaalbert

A function declared to be available inside the RepyV2 namespace via one of namespace.py's *_WRAPPER_INFO wrapper dicts may list Dict() as (one of) its args processor(s). A call from within the sandbox into such function causes the argument(s) to be _copyed. Now certain dictionary contents cause problems during copying, particularly those that use types as values.

For instance, virtualnamespace.evaluate takes a dict or SafeDict argument. Supplying a dict with a problematic value like so,

v = createvirtualnamespace("", "")
v.evaluate({"abc": str}) # Ouch

breaks as namespace._copy raises Exception (with class 'namespace.NamespaceInternalError'): _copy failed on {'abc': <type 'str'>} with message _copy failed on <type 'str'> with message _copy is not implemented for objects of type <function safe_type at 0x10d0021b8>. The issue is that str is a type, or more accurately a safe.safe_type, and there is no handling for that in _copy.

Funnily enough, the problem is avoided by providing a SafeDict with the same contents, because the SafeDict makes a different clause in _copy match. The difference is that SafeDicts are instances / types.InstanceTypes.

v = createvirtualnamespace("", "")
v.evaluate(SafeDict({"abc": str})) # Success!

The superficial fix for this corner case of a corner case of a bit of funtionality I've never seen anyone use is to add safe.safe_type to the list of types that namespace._copy checks the type of its argument, obj, against. Whether or not dicts should be treated all that differently from SafeDicts as they traverse the namespace boundary is a different question though.


Historical note: I found this problem via the original virtualnamespace context safety unit test, although that test was not supposed the above problem: https://github.com/SeattleTestbed/repy_v2/blob/4db9ecd48a4577d646e4c38cf1af634dd8600810/testsV2/ut_repyv2api_virtualnamespacecontextsafety.py .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions