Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Issues with hosting in sandbox AppDomain in 64bit process #1182

Open
sasha-uk opened this issue Mar 11, 2015 · 1 comment
Open

Issues with hosting in sandbox AppDomain in 64bit process #1182

sasha-uk opened this issue Mar 11, 2015 · 1 comment

Comments

@sasha-uk
Copy link

The following code gives unexpected results if executed in 64bit process (.NET45).

class Program
{
    static void Main(string[] args)
    {
        var appDomainSetup = new AppDomainSetup { ApplicationBase = Environment.CurrentDirectory };
        var permissionSet = new PermissionSet(PermissionState.None);
        permissionSet.AddPermission(new SecurityPermission(PermissionState.Unrestricted));
        permissionSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted));
        permissionSet.AddPermission(new ReflectionPermission(PermissionState.Unrestricted));
        var appDomain = AppDomain.CreateDomain("PhytonSandbox", null, appDomainSetup, permissionSet);
        var sandbox = (Sandbox)appDomain.CreateInstanceAndUnwrap(typeof(Sandbox).Assembly.FullName, typeof(Sandbox).FullName);

        sandbox.Execute("print \"{0}\".format(42.1234)");
        sandbox.Execute("import math" + Environment.NewLine + 
                        "print \"{0}\".format(math.fabs(-1))");
        Console.ReadLine();
    }

    public class Sandbox : MarshalByRefObject
    {
        public void Execute(string script)
        {
            var scriptEngine = Python.CreateEngine();
            var source = scriptEngine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
            var compiledCode = source.Compile();
            var scope = scriptEngine.CreateScope();
            compiledCode.Execute(scope);
        }
    }
}

OUTPUT ON 32bit (CORRECT)
42.1234
1.0

OUTPUT ON 64bit (INCORRECT)
1.2e-314
0.0

Changing the permission set to PermissionSet(PermissionState.Unrestricted) will result in the correct output on 64bit.

IronPython version 2.7.5.1000

@slide
Copy link
Contributor

slide commented Aug 10, 2016

Do you just set the output mode for the assembly to 64bit?

@slide slide removed the untriaged label Aug 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants