Error importing xaml with single quotes (looked like buffer overflow) in Unity
Posted: 08 May 2017, 08:09
Edit: updated title to better help others
Tried opening bug but the bug report interface says "you have no permissions to access bug<something>.php> on this server" when I click Submit Report
Note: this bug is blocking our XAML development
Here's the issue:
Buffer overflow in Noesis loading a simple XAML with two rectangles and animations
When I try to import CropFramePhone.xaml file (attached, 45 lines XAML) I get an ArgumentException about "Illegal characters in path in NoesisPostprocessor.cs.
When I changed the code to log the path, I noticed it is a broken string - looks like some XAML overwrote the string null terminating character in memory. See bold section below
1. Create new Unity3d 3D Project
2. Add Noesis, ensure "show preview" is selected in Noesis Settings
3. Copy attached CropFramePhone.xaml to Assets
Expected:
all imports OK
Actual:
ArgumentException: Illegal characters in path.
System.IO.Path.IsPathRooted (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:508)
System.IO.Path.InsecureGetFullPath (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:357)
System.IO.Path.GetFullPath (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:289)
NoesisPostprocessor.NormalizePath (System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:97)
NoesisPostprocessor.AbsolutePath (System.String parent, System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:134)
NoesisPostprocessor.ScanFonts (.NoesisXaml xaml, System.String directory, System.String text) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:247)
NoesisPostprocessor.ScanDependencies (.NoesisXaml xaml, System.String directory) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:297)
NoesisPostprocessor.ImportXaml (.NoesisXaml xaml, System.String directory, System.IO.FileStream file) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:308)
NoesisPostprocessor.ImportXaml (System.String filename) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:322)
NoesisPostprocessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:50)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:27)
To debug, after getting the exception in Steps to Reproduce, add the below try..catch in NormalizePath in NoesisPostprocessor.cs around line 93:
Run again. Reimport the XAML. Notice the path string is not null terminated - some memory was overwritten during import.
ArgumentException: Path: *Assets/
<Rectangle StrokeThickness='0' Height='1' Fill='*
NoesisPostprocessor.NormalizePath (System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:102)
NoesisPostprocessor.AbsolutePath (System.String parent, System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:134)
NoesisPostprocessor.ScanFonts (.NoesisXaml xaml, System.String directory, System.String text) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:247)
NoesisPostprocessor.ScanDependencies (.NoesisXaml xaml, System.String directory) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:297)
NoesisPostprocessor.ImportXaml (.NoesisXaml xaml, System.String directory, System.IO.FileStream file) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:308)
NoesisPostprocessor.ImportXaml (System.String filename) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:322)
NoesisPostprocessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:50)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:27)
XAML to repro (name it CropFramePhone.xaml):
Tried opening bug but the bug report interface says "you have no permissions to access bug<something>.php> on this server" when I click Submit Report
Note: this bug is blocking our XAML development
Here's the issue:
Buffer overflow in Noesis loading a simple XAML with two rectangles and animations
When I try to import CropFramePhone.xaml file (attached, 45 lines XAML) I get an ArgumentException about "Illegal characters in path in NoesisPostprocessor.cs.
When I changed the code to log the path, I noticed it is a broken string - looks like some XAML overwrote the string null terminating character in memory. See bold section below
1. Create new Unity3d 3D Project
2. Add Noesis, ensure "show preview" is selected in Noesis Settings
3. Copy attached CropFramePhone.xaml to Assets
Expected:
all imports OK
Actual:
ArgumentException: Illegal characters in path.
System.IO.Path.IsPathRooted (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:508)
System.IO.Path.InsecureGetFullPath (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:357)
System.IO.Path.GetFullPath (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Path.cs:289)
NoesisPostprocessor.NormalizePath (System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:97)
NoesisPostprocessor.AbsolutePath (System.String parent, System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:134)
NoesisPostprocessor.ScanFonts (.NoesisXaml xaml, System.String directory, System.String text) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:247)
NoesisPostprocessor.ScanDependencies (.NoesisXaml xaml, System.String directory) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:297)
NoesisPostprocessor.ImportXaml (.NoesisXaml xaml, System.String directory, System.IO.FileStream file) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:308)
NoesisPostprocessor.ImportXaml (System.String filename) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:322)
NoesisPostprocessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:50)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:27)
To debug, after getting the exception in Steps to Reproduce, add the below try..catch in NormalizePath in NoesisPostprocessor.cs around line 93:
Code: Select all
private static string NormalizePath(string uri)
{
try
{
string full = Path.GetFullPath(uri).Replace('\\', '/');
return full.Substring(full.IndexOf("Assets/"));
}
catch (ArgumentException)
{
throw new ArgumentException("Path: *" + uri + "*");
}
}ArgumentException: Path: *Assets/
<Rectangle StrokeThickness='0' Height='1' Fill='*
NoesisPostprocessor.NormalizePath (System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:102)
NoesisPostprocessor.AbsolutePath (System.String parent, System.String uri) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:134)
NoesisPostprocessor.ScanFonts (.NoesisXaml xaml, System.String directory, System.String text) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:247)
NoesisPostprocessor.ScanDependencies (.NoesisXaml xaml, System.String directory) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:297)
NoesisPostprocessor.ImportXaml (.NoesisXaml xaml, System.String directory, System.IO.FileStream file) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:308)
NoesisPostprocessor.ImportXaml (System.String filename) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:322)
NoesisPostprocessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:50)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:27)
XAML to repro (name it CropFramePhone.xaml):
Code: Select all
<UserControl x:Class="Adorners.Frames.CropFramePhone"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<Grid d:DesignHeight="300" d:DesignWidth="400" UseLayoutRounding="True">
<Grid.Resources>
<Storyboard x:Name="animFadeIn">
<DoubleAnimation To="1" Storyboard.TargetName="gridGuides" Storyboard.TargetProperty="Opacity" BeginTime="0:0:0.3" Duration="0:0:0.5">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
<Storyboard x:Name="animFadeOut">
<DoubleAnimation To="0" Storyboard.TargetName="gridGuides" Storyboard.TargetProperty="Opacity" Duration="0:0:0.5">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</Grid.Resources>
<Grid x:Name="gridGuides" Opacity="0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="1.6180339887*"/>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="1.6180339887*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Rectangle StrokeThickness='0' Height='1' Fill='#60FFFFFF' Grid.ColumnSpan='3' HorizontalAlignment='Stretch' Grid.Row='1' VerticalAlignment='Top' />
<Rectangle StrokeThickness='0' Height='1' Fill='#60FFFFFF' Grid.ColumnSpan='3' HorizontalAlignment='Stretch' Grid.Row='2' VerticalAlignment='Top' />
</Grid>
</Grid>
</UserControl>