Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

[AIR 51.0.1.1] Using `Stage` from native extension cause "`Error #2070: Security sandbox violation`" while `NetStream` in "Data Generation Mode"

Open itlancer opened this issue 3 months ago • 1 comments

Problem Description

Using Stage methods from native extension cause "Error #2070: Security sandbox violation" while NetStream in "Data Generation Mode". Happens only with latest AIR 51.0.1.1. Seems broken after fix https://github.com/airsdk/Adobe-Runtime-Support/issues/3098.

Tested with AIR 51.0.1.1 with multiple different Windows and Linux devices with different applications. There is no such issue using AIR 50.2.5.1 and 51.0.0.4. There is no such issue without NetStream in "Data Generation Mode".

Related issues: https://github.com/airsdk/Adobe-Runtime-Support/issues/2296 https://github.com/airsdk/Adobe-Runtime-Support/issues/2277 https://github.com/airsdk/Adobe-Runtime-Support/issues/2163 https://github.com/airsdk/Adobe-Runtime-Support/issues/2159 https://github.com/airsdk/Adobe-Runtime-Support/issues/1984 https://github.com/airsdk/Adobe-Runtime-Support/issues/365 https://github.com/airsdk/Adobe-Runtime-Support/issues/224 https://github.com/airsdk/Adobe-Runtime-Support/issues/180 https://github.com/airsdk/Adobe-Runtime-Support/issues/171 https://github.com/airsdk/Adobe-Runtime-Support/issues/155 https://github.com/airsdk/Adobe-Runtime-Support/issues/139

Steps to Reproduce

Launch application with code below and click anywhere on stage.

Application example with sources attached. netstream_play_null_native_extension_stage_bug.zip

Application code:

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import com.test.ane.TestANE;
	import flash.events.MouseEvent;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.media.Video;
	import flash.events.NetStatusEvent;
	import flash.net.NetStreamAppendBytesAction;
	import flash.utils.ByteArray;
	
	public class NetStreamPlayNullNativeExtensionStageBug extends Sprite {
		private var testANE:TestANE;
		
		private var nc:NetConnection;
		private var ns:NetStream;
		private var video:Video = new Video(640, 480);
		
		[Embed(source = "video.flv", mimeType = "application/octet-stream")]
		public var VideoFile:Class;
		
		public function NetStreamPlayNullNativeExtensionStageBug() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			testANE = new TestANE();
			
			addChild(video);
			
			nc = new NetConnection();
			nc.addEventListener(NetStatusEvent.NET_STATUS, ncHandler);
			nc.connect(null);
			
			stage.addEventListener(MouseEvent.CLICK, click);
		}
	
		private function ncHandler(e:NetStatusEvent):void {
			trace("e.info.code", e.info.code);			
			if (e.info.code == "NetConnection.Connect.Success"){
				ns = new NetStream(nc);
				ns.client = {onMetaData:getMeta};
				ns.addEventListener(NetStatusEvent.NET_STATUS, nsHandler);
				video.attachNetStream(ns);
				ns.play(null);
				
				var videoBytes:ByteArray = new VideoFile();
				ns.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);
				ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
				ns.appendBytes(new VideoFile());
			}
		}

		private function nsHandler(e:NetStatusEvent):void {
			trace(e.info.code);
		}

		private function getMeta(mdata:Object):void { }
		
		private function click(e:MouseEvent):void {
			trace("click");
			testANE.test(stage);//This call cause SecurityError: Error #2070: Security sandbox violation: caller app:/com.test.ane cannot access Stage owned by app:/netstream_play_null_native_extension_stage_bug.swf.
		}
	}
}

Native extension code:

package com.test.ane {
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.TouchEvent;
	import flash.events.EventDispatcher;
	
	//Just a sample of native extension
	public class TestANE extends Sprite {
		
		public function TestANE() {
			
		}
		
		public function test(_stage:Stage):void {
			//Any of these lines cause SecurityError: Error #2070: Security sandbox violation: caller app:/com.test.ane cannot access Stage owned by app:/netstream_play_null_native_extension_stage_bug.swf.
			trace(_stage.displayState);
			_stage.addEventListener(TouchEvent.TOUCH_BEGIN, touchBegin);
		}
		
		private function touchBegin(e:TouchEvent):void {
			
		}
	}
}

Actual Result: Exception:

SecurityError: Error #2070: Security sandbox violation: caller app:/com.test.ane cannot access Stage owned by app:/netstream_play_null_native_extension_stage_bug.swf.
	at flash.display::Stage/get displayState()
	at com.test.ane::TestANE/test()
	at NetStreamPlayNullNativeExtensionStageBug/click()

Expected Result: Call Stage methods without exceptions.

Known Workarounds

none *use AIR 50.2.5.1 or earlier.

itlancer avatar May 06 '24 19:05 itlancer