You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Xslt document function fails when path Contains Private Area Unicode Characters #59353
Initializing an XmlReader using XmlReader.Create(<path-to-file>) where the path contains characters from the unicode private use area causes issues at file load. Part of the path that's the culprit: Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[]
The workaround is to call XmlReader.Create using a StreamReader. However, when MSBuild is calling its XslTransform task on a file in this type of path, and in the xsl file it calls the Document function on a file that also exists in a path like this, it will break. See details here: dotnet/msbuild#6863 (comment)
You'll need to include U1[]U2[]U3[] as part of the path. Adding that and using your code in an empty console proj caused the repro for me.
ghost added
needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
In summary, when transforming an xslt doc who's path contains the unicode mess (Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[]), you'll hit an XslTransformException if that xslt calls the document function to find another xml file next to it.
changed the title [-]XmlReader.Create Fails When Path Contains Private Area Unicode Characters[/-][+]Xslt document function fails when path Contains Private Area Unicode Characters[/+]on Oct 5, 2021
Also this isn't a blocking issue. We worked around one aspect of the issue which was loading the xslt doc in the first place. But we also see the error when trying to load another document while transforming the first.
Steps to reproduce:
Download zip, create a folder next to proj1.csproj called Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[]. Drag transform.xslt and b.xml into it.
Note: If you have the latest and greatest VS, it probably already has this change. So msbuild <pathtoproj1>.csproj on a dev command prompt should suffice. If not, do the steps below:
git clone https://github.com/dotnet/msbuild
cd msbuild
build.cmd /p:CreateBootstrap=true
cd artifacts\bin\bootstrap\net472\MSBuild\Current\Bin
msbuild.exe <pathtoproj1.csproj>
You should get the error error MSB3703: Unable to execute transformation. An error occurred while loading document 'b.xml'. See InnerException for a complete description of the error.. After you've confirmed the repro, debug into it to see the inner exception.
Open up MSBuild.Dev.slnf in VS.
On same command line: set MSBUILDDEBUGONSTART=1
msbuild.exe <pathtoproj1.csproj>
Place a breakpoint in the line I mentioned the exception gets thrown (2 comments above)
IMO this seems to be caused by unexpected behaviour in System.Uri: specifically, a PUA character is not roundtripped through a file:/// URI for new Uri(x).LocalPath.
This test program tests the Uri constructor with various characters that have different UTF-8 encoded lengths; the last is a PUA character:
I haven't consulted the URI RFC to determine whether this would be considered correct. You don't get the same failure to round-trip for $@"https://example.com/{name}.txt" so I suspect not.
If System.Uri can't be changed in this instance (for back-compat concerns), then XmlUriResolver and/or XmlDownloadManager might need to work around the double-encoding?
I guess, since you can pass your own XmlResolver possibly you can just derive and apply workaround in the new type. We should still figure out if this is XML or Uri issue. The Dangerous* setting doesn't sound like a good idea but I'm not sure what are the exact implications of that or why it was created.
@karelz do we have any Uri experts who could help with the questions above?
Activity
krwq commentedon Oct 1, 2021
@benvillalobos can you provide a minimal repro? Ideally something which creates a file on the fly and uses
\uXYZVnotation for non-english charactersand getting no exception.
What's the exception you're getting?
benvillalobos commentedon Oct 1, 2021
You'll need to include
U1[]U2[]U3[]as part of the path. Adding that and using your code in an empty console proj caused the repro for me.krwq commentedon Oct 5, 2021
@benvillalobos what is the exception you're seeing?
krwq commentedon Oct 5, 2021
from the e-mail conversation this might be blocking msbuild team so changing milestone
benvillalobos commentedon Oct 5, 2021
OH, apologies. The title for this issue was incorrect. See this comment for details: dotnet/msbuild#6863 (comment)
Exception gets thrown on this line https://github.com/dotnet/msbuild/blob/main/src/Tasks/XslTransformation.cs#L176
In summary, when transforming an xslt doc who's path contains the unicode mess (
Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[]), you'll hit an XslTransformException if that xslt calls thedocumentfunction to find another xml file next to it.[-]XmlReader.Create Fails When Path Contains Private Area Unicode Characters[/-][+]Xslt document function fails when path Contains Private Area Unicode Characters[/+]benvillalobos commentedon Oct 5, 2021
Also this isn't a blocking issue. We worked around one aspect of the issue which was loading the xslt doc in the first place. But we also see the error when trying to load another document while transforming the first.
krwq commentedon Oct 5, 2021
@benvillalobos any chance you could create a project with a tiny repro?
benvillalobos commentedon Oct 6, 2021
proj1.zip
Steps to reproduce:
Download zip, create a folder next to proj1.csproj called
Ⅻㄨㄩ 啊阿鼾齄丂丄狚狛狜狝﨨﨩ˊˋ˙–⿻〇㐀㐁䶴䶵U1[]U2[]U3[]. Drag transform.xslt and b.xml into it.Note: If you have the latest and greatest VS, it probably already has this change. So
msbuild <pathtoproj1>.csprojon a dev command prompt should suffice. If not, do the steps below:You should get the error
error MSB3703: Unable to execute transformation. An error occurred while loading document 'b.xml'. See InnerException for a complete description of the error.. After you've confirmed the repro, debug into it to see the inner exception.Open up MSBuild.Dev.slnf in VS.
On same command line:
set MSBUILDDEBUGONSTART=1msbuild.exe <pathtoproj1.csproj>
Place a breakpoint in the line I mentioned the exception gets thrown (2 comments above)
bgrainger commentedon Nov 26, 2021
IMO this seems to be caused by unexpected behaviour in
System.Uri: specifically, a PUA character is not roundtripped through afile:///URI fornew Uri(x).LocalPath.This test program tests the
Uriconstructor with various characters that have different UTF-8 encoded lengths; the last is a PUA character:The output shows that the file path does round-trip for everything except the PUA character, which is double-encoded in the URI.
I haven't consulted the URI RFC to determine whether this would be considered correct. You don't get the same failure to round-trip for
$@"https://example.com/{name}.txt"so I suspect not.If
System.Urican't be changed in this instance (for back-compat concerns), thenXmlUriResolverand/orXmlDownloadManagermight need to work around the double-encoding?bgrainger commentedon Nov 26, 2021
I wonder if
System.Uriparsing for file paths goes through the IRI code path, which explicitly excludes PUA characters (as per https://datatracker.ietf.org/doc/html/rfc3987#section-2.2):runtime/src/libraries/System.Private.Uri/src/System/IriHelper.cs
Lines 16 to 22 in c00b068
A fix would be to change this line of code as follows:
runtime/src/libraries/System.Private.Xml/src/System/Xml/XmlResolver.cs
Line 43 in c00b068
However, I don't know the security implications of this, given the property name.
krwq commentedon Dec 8, 2021
I guess, since you can pass your own XmlResolver possibly you can just derive and apply workaround in the new type. We should still figure out if this is XML or Uri issue. The
Dangerous*setting doesn't sound like a good idea but I'm not sure what are the exact implications of that or why it was created.@karelz do we have any Uri experts who could help with the questions above?