pantsbuild / scie-pants

Protects your Pants from the elements.
https://www.pantsbuild.org/docs/installation
Apache License 2.0
19 stars 20 forks source link

Pants fails on non-utf8 env variables #198

Closed kamil-muszynski-90poe closed 1 year ago

kamil-muszynski-90poe commented 1 year ago

We have came across this error when running pants:

$ env $'FOO=B\xa5R' pants --version          

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "B\xA5R"', library/std/src/env.rs:171:83
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This happens on scie-pants 0.8.1 and pants 2.16.x

Some of the devs had non utf8 characters in env variables on their working PCs - even if not related to pants, it were causing the error as above.

I was told this may be an error in scie-pants - I apologize if that's not the case. Looks like https://github.com/rust-lang/rust/blob/master/library/std/src/env.rs fails to parse such values, but maybe this can be avoided if those vars are not at all related to pants launcher?

Related slack thread: https://pantsbuild.slack.com/archives/C046T6T9U/p1685433634178729

jsirois commented 1 year ago

A convenient repro case on Linux is:

$ FOO=`cat /bin/sh | head -1 | cut -b 1-25` pants -V
-bash: warning: command substitution: ignored null byte in input
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "\u{7f}ELF\u{2}\u{1}\u{1}\u{3}>\u{1}\xF0"', library/std/src/env.rs:171:83
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Of course @kamil-muszynski-90poe provided an even more convenient example for Unix. I had to come up with a different example for Windows WTF-16 though.

jsirois commented 1 year ago

Ok, the issue is actually over here in scie-jump which scie-pants is built with: https://github.com/a-scie/jump/blob/faa65b7875c1eee5fa902d81138782b6f1d00232/jump/src/process.rs#L65-L66

Filed https://github.com/a-scie/jump/issues/105

jsirois commented 1 year ago

@kamil-muszynski-90poe you can now update to scie-pants 0.8.2 with its fix: https://github.com/pantsbuild/scie-pants/releases/tag/v0.8.2

You'll still be blocked though by Pants itself which will fail to work with pantsd; so you can only use --no-pantsd for now until https://github.com/pantsbuild/pants/issues/19199 is fixed.