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

Loading long env value from a file is crashing Node on Windows #52248

Closed
kibertoad opened this issue Mar 28, 2024 · 13 comments
Closed

Loading long env value from a file is crashing Node on Windows #52248

kibertoad opened this issue Mar 28, 2024 · 13 comments
Labels
confirmed-bug Issues with confirmed bugs. dotenv Issues and PRs related to .env file parsing windows Issues and PRs related to the Windows platform.

Comments

@kibertoad
Copy link
Contributor

kibertoad commented Mar 28, 2024

Version

20.12.0

Platform

Windows 11

Subsystem

process

What steps will reproduce the bug?

Try loading .env file with the following entry in it:

JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzi4k4ful8Q65RWbHvZwD
jKNfspb89typkUATf8KXlYcWp6ibUG9nKpYrig3jmlCdMvCm+S7kZedACshFyRmm
1ocaWjRIt/jJyzntxnMIgWetTedZXXzlFbparDMrdEMmsPbM7LrByCU57iKloZEl
BhOSQZk/JbJK1YpozTCxcs28YlpnTuMBaXvXddrQuNHo+HYhK53XlFXyiOBzmEFY
cBrVqptdjA3z7uNNd6A4IAfEkRYp4lZxZgwTPyjYZ1oXmhalvbr6OAs9ujLIZPSM
QoP1VoHLdOqrs7QTmi2rrNCfIcFkFp02N39TovMm9zZQJjQvFEJqIKe4db2457vr
uJ5qxkWmbBu+/tf6ytKfbiA433neLSvpfquPXbq3OLGzJ4H2YHiHa0ddfUCqdN49
t5nCPEMp6OTa5kXuwObf8yvHyoP8HgQQD+/sftHUIE/1sdQ6fzB/9L+smzp5SW/X
nI8NY0k1SH9MLlweGuXi6M1jS62kPWk4HTDQmiqUTImcG0XYRrVd5ISXPdfnVgnq
KKht+SUmkPrfaWMDc21FsXXmmVSRTjvBhA6Cy6PLPzGZaeA4TVkOZUkp1OvcyfiI
HixuZca1OASxGeUM8lcPi9my8TJCtw5ZR0M/uqVV/1o3U0nx+U5z54ulWN9leMLY
vgv+lGrqfFWRemajGXSm8L0CAwEAAQ==
-----END PUBLIC KEY-----"

by running this code:

import { loadEnvFile } from 'node:process'

loadEnvFile('./.env')

This fails with an error Process finished with exit code -1073740791 (0xC0000409)

How often does it reproduce? Is there a required condition?

It is always reproduceable

What is the expected behavior? Why is that the expected behavior?

The value should be loaded correctly. This works with dotenv.

What do you see instead?

An error Process finished with exit code -1073740791 (0xC0000409)

Additional information

No response

@kibertoad kibertoad changed the title Multine env value is crashing Node Multiline env value is crashing Node Mar 28, 2024
@kibertoad
Copy link
Contributor Author

Related to #51289

@kibertoad
Copy link
Contributor Author

@IlyasShabi Maybe you have thoughts on this?

@mertcanaltin
Copy link
Member

@IlyasShabi Maybe you have thoughts on this?

I have opened a pr aimed at solving this problem

@IlyasShabi
Copy link
Contributor

@mertcanaltin thanks for sending a PR I will review it asap

@IlyasShabi
Copy link
Contributor

@mertcanaltin @kibertoad Have you tried to reproduce it on a mac os? I'm unable to reproduce it on my end 🤔 it might be related to Windows maybe

@anonrig
Copy link
Member

anonrig commented Mar 30, 2024

I couldn't reproduce it. Also, you don't need to call node:process since process is a global variable:

node on  main via ⬢ v21.7.1
❯ cat .env
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzi4k4ful8Q65RWbHvZwD
jKNfspb89typkUATf8KXlYcWp6ibUG9nKpYrig3jmlCdMvCm+S7kZedACshFyRmm
1ocaWjRIt/jJyzntxnMIgWetTedZXXzlFbparDMrdEMmsPbM7LrByCU57iKloZEl
BhOSQZk/JbJK1YpozTCxcs28YlpnTuMBaXvXddrQuNHo+HYhK53XlFXyiOBzmEFY
cBrVqptdjA3z7uNNd6A4IAfEkRYp4lZxZgwTPyjYZ1oXmhalvbr6OAs9ujLIZPSM
QoP1VoHLdOqrs7QTmi2rrNCfIcFkFp02N39TovMm9zZQJjQvFEJqIKe4db2457vr
uJ5qxkWmbBu+/tf6ytKfbiA433neLSvpfquPXbq3OLGzJ4H2YHiHa0ddfUCqdN49
t5nCPEMp6OTa5kXuwObf8yvHyoP8HgQQD+/sftHUIE/1sdQ6fzB/9L+smzp5SW/X
nI8NY0k1SH9MLlweGuXi6M1jS62kPWk4HTDQmiqUTImcG0XYRrVd5ISXPdfnVgnq
KKht+SUmkPrfaWMDc21FsXXmmVSRTjvBhA6Cy6PLPzGZaeA4TVkOZUkp1OvcyfiI
HixuZca1OASxGeUM8lcPi9my8TJCtw5ZR0M/uqVV/1o3U0nx+U5z54ulWN9leMLY
vgv+lGrqfFWRemajGXSm8L0CAwEAAQ==
-----END PUBLIC KEY-----"

node on  main via ⬢ v21.7.1
❯ cat hello.js
process.loadEnvFile('./.env');
console.log(process.env.JWT_PUBLIC_KEY);

node on  main via ⬢ v21.7.1
❯ node hello.js
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzi4k4ful8Q65RWbHvZwD
jKNfspb89typkUATf8KXlYcWp6ibUG9nKpYrig3jmlCdMvCm+S7kZedACshFyRmm
1ocaWjRIt/jJyzntxnMIgWetTedZXXzlFbparDMrdEMmsPbM7LrByCU57iKloZEl
BhOSQZk/JbJK1YpozTCxcs28YlpnTuMBaXvXddrQuNHo+HYhK53XlFXyiOBzmEFY
cBrVqptdjA3z7uNNd6A4IAfEkRYp4lZxZgwTPyjYZ1oXmhalvbr6OAs9ujLIZPSM
QoP1VoHLdOqrs7QTmi2rrNCfIcFkFp02N39TovMm9zZQJjQvFEJqIKe4db2457vr
uJ5qxkWmbBu+/tf6ytKfbiA433neLSvpfquPXbq3OLGzJ4H2YHiHa0ddfUCqdN49
t5nCPEMp6OTa5kXuwObf8yvHyoP8HgQQD+/sftHUIE/1sdQ6fzB/9L+smzp5SW/X
nI8NY0k1SH9MLlweGuXi6M1jS62kPWk4HTDQmiqUTImcG0XYRrVd5ISXPdfnVgnq
KKht+SUmkPrfaWMDc21FsXXmmVSRTjvBhA6Cy6PLPzGZaeA4TVkOZUkp1OvcyfiI
HixuZca1OASxGeUM8lcPi9my8TJCtw5ZR0M/uqVV/1o3U0nx+U5z54ulWN9leMLY
vgv+lGrqfFWRemajGXSm8L0CAwEAAQ==
-----END PUBLIC KEY-----

@anonrig
Copy link
Member

anonrig commented Mar 30, 2024

I couldn't reproduce it on main branch as well.

@kibertoad
Copy link
Contributor Author

@anonrig @IlyasShabi I can confirm that this only happens in Windows. E. g. https://github.com/lokalise/node-service-template/actions/runs/8491928125/job/23264398029?pr=536 is green, but same tests are failing locally for me.

@kibertoad kibertoad changed the title Multiline env value is crashing Node Multiline env value is crashing Node on Windows Mar 30, 2024
@anonrig
Copy link
Member

anonrig commented Mar 30, 2024

I reproduced this on Node.js Windows CI

@anonrig anonrig added confirmed-bug Issues with confirmed bugs. windows Issues and PRs related to the Windows platform. dotenv Issues and PRs related to .env file parsing labels Mar 30, 2024
@kibertoad kibertoad changed the title Multiline env value is crashing Node on Windows Loading long env value from a file is crashing Node on Windows Mar 31, 2024
@mertcanaltin
Copy link
Member

Would it be a good idea to process the values by chunking them?

@kibertoad
Copy link
Contributor Author

@IlyasShabi Was the fix included in 22.0.0? I've tried running it, and it's still crashing with the same error when trying to load this value:

JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAzi4k4ful8Q65RWbHvZwD
jKNfspb89typkUATf8KXlYcWp6ibUG9nKpYrig3jmlCdMvCm+S7kZedACshFyRmm
1ocaWjRIt/jJyzntxnMIgWetTedZXXzlFbparDMrdEMmsPbM7LrByCU57iKloZEl
BhOSQZk/JbJK1YpozTCxcs28YlpnTuMBaXvXddrQuNHo+HYhK53XlFXyiOBzmEFY
cBrVqptdjA3z7uNNd6A4IAfEkRYp4lZxZgwTPyjYZ1oXmhalvbr6OAs9ujLIZPSM
QoP1VoHLdOqrs7QTmi2rrNCfIcFkFp02N39TovMm9zZQJjQvFEJqIKe4db2457vr
uJ5qxkWmbBu+/tf6ytKfbiA433neLSvpfquPXbq3OLGzJ4H2YHiHa0ddfUCqdN49
t5nCPEMp6OTa5kXuwObf8yvHyoP8HgQQD+/sftHUIE/1sdQ6fzB/9L+smzp5SW/X
nI8NY0k1SH9MLlweGuXi6M1jS62kPWk4HTDQmiqUTImcG0XYRrVd5ISXPdfnVgnq
KKht+SUmkPrfaWMDc21FsXXmmVSRTjvBhA6Cy6PLPzGZaeA4TVkOZUkp1OvcyfiI
HixuZca1OASxGeUM8lcPi9my8TJCtw5ZR0M/uqVV/1o3U0nx+U5z54ulWN9leMLY
vgv+lGrqfFWRemajGXSm8L0CAwEAAQ==
-----END PUBLIC KEY-----"

@IlyasShabi
Copy link
Contributor

@kibertoad According to this https://github.com/nodejs/node/releases/tag/v22.0.0 I think it was not released

@kibertoad
Copy link
Contributor Author

Gotcha, thanks! Here's hoping it will be included into subsequent releases. As it wasn't a semver major, it should be possible to include it at any point.

aduh95 pushed a commit that referenced this issue Apr 29, 2024
PR-URL: #52406
Fixes: #52248
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
marco-ippolito pushed a commit that referenced this issue May 2, 2024
PR-URL: #52406
Fixes: #52248
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
marco-ippolito pushed a commit that referenced this issue May 3, 2024
PR-URL: #52406
Fixes: #52248
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. dotenv Issues and PRs related to .env file parsing windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

4 participants