kubernetes-client / javascript

Javascript client
Apache License 2.0
1.96k stars 495 forks source link

Exec stdin might lost data if pass in `Readable.from(string)` #1772

Open hax opened 6 days ago

hax commented 6 days ago

https://github.com/kubernetes-client/javascript/blob/b4fd82f2d20e46ad6a60f9b83c38553f5674a4dc/src/web-socket-handler.ts#L58

Current implementation assume stdin is always a binary stream, but it does not really check the type. So if pass Readable.from(string) as stdin, most time it works, unless the string contains non-ASCII characters, in such case, data is string and data.length is number of UTF16 code units, which will smaller than the number of UTF8 code units or bytes.

I suggest the implementation should either deal with the string case, or just throw type error if not buffer.

brendandburns commented 6 days ago

Happy to take a PR with a unit test to repro this and either fix that you prefer.