Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dotnet): crash when TEMP contains certain unicode characters #1913

Merged
merged 4 commits into from
Aug 18, 2020

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Aug 18, 2020

In certain environments, the temporary directory path may contain
unicode characters. If those are not properly encoded as UTF-8 when sent
to the @jsii/kernel process, a failure will occur when trying to
access such paths.

This change contains fixes for two possible sources of problems in such
situations:

  1. In @jsii/runtime, the SyncStdio class was a little too eager in
    turning it's Buffer to UTF-8 strings, as it could have only a part
    of a multi-byte character sequence (the conversion would then fail
    or result in corruption). Instead, it now looks for \n directly on
    the Buffer, and only performs string conversion once one has been
    found.
  2. In the .NET Runtime, the NodeProcess class would spawn using the
    System.Diagnostic.Process class without specifying input and output
    encodings, which by default are the System.Console encoding. If
    that happens to not be UTF-8, the result could be unreliable.
    Instead, the encodings are now forced to System.Text.Encoding.UTF8
    for all three pipes of the child process (Input, Output and
    Error).

Reproducing the conditions for the failure reported in aws/aws-cdk#7456 is
somewhat difficult, especially in the context of CI/CD. This makes it difficult
to validate those fixes actually deliver on their promises.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

In certain environments, the temporary directory path may contain
unicode characters. If those are not properly encoded as UTF-8 when sent
to the `@jsii/kernel` process, a failure will occur when trying to
access such paths.

This change contains fixes for two possible sources of problems in such
situations:

1. In `@jsii/runtime`, the `SyncStdio` class was a little too eager in
   turning it's `Buffer` to UTF-8 strings, as it could have only a part
   of a multi-byte character sequence (the conversion would then fail
   or result in corruption). Instead, it now looks for `\n` directly on
   the `Buffer`, and only performs string conversion once one has been
   found.
2. In the .NET Runtime, the `NodeProcess` class would spawn using the
   `System.Diagnostic.Process` class without specifying input and output
   encodings, which by default are the `System.Console` encoding. If
   that happens to not be `UTF-8`, the result could be unreliable.
   Instead, the encodings are now forced to `System.Text.Encoding.UTF8`
   for all three pipes of the child process (`Input`, `Output` and
   `Error`).

Reproducing the conditions for the failure reported in #7456 is somewhat
difficult, especially in the context of CI/CD. This makes it difficult
to validate those fixes actually deliver on their promises.

Fixes #7456
@RomainMuller RomainMuller requested a review from a team August 18, 2020 10:07
@RomainMuller RomainMuller self-assigned this Aug 18, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 18, 2020
@RomainMuller RomainMuller force-pushed the rmuller/path-encoding-weirdness branch from d1f2a9f to c5b5e26 Compare August 18, 2020 10:59
@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Aug 18, 2020
@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 19176dd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@RomainMuller RomainMuller merged commit 8f31b1a into master Aug 18, 2020
@RomainMuller RomainMuller deleted the rmuller/path-encoding-weirdness branch August 18, 2020 16:24
@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants