fix(agent): add OEM code page transcoding in Devolutions Agent#1780
fix(agent): add OEM code page transcoding in Devolutions Agent#1780Vladyslav Nikonov (vnikonov-devolutions) wants to merge 1 commit into
Conversation
Let maintainers know that an action is required on their side
|
There was a problem hiding this comment.
Pull request overview
This PR adds Windows console/OEM code page handling for exec session IO redirection in devolutions-session, enabling correct UTF-8 behavior over NowProto (including a new UNICODE_CONSOLE mode that switches shells to UTF-8).
Changes:
- Introduces a Windows codepage transcoding module (
DataEncoding,InputEncoder,OutputDecoder) to convert stdout/stderr to UTF-8 and stdin from UTF-8 when appropriate. - Wires per-session/process encoding selection into exec styles (process, batch, Windows PowerShell, PowerShell 7+), including UTF-8 console injection for
UNICODE_CONSOLE. - Extends temp file helpers to write scripts in specific encodings (OEM-transcoded, UTF-8 with BOM).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
devolutions-session/src/dvc/task.rs |
Selects IO/script encodings per exec operation; adds UNICODE_CONSOLE support and encoding-aware process builder usage. |
devolutions-session/src/dvc/process.rs |
Adds encoding to process context and performs streaming stdin/stdout/stderr transcoding (including flush on EOF). |
devolutions-session/src/dvc/mod.rs |
Exposes the new encoding module. |
devolutions-session/src/dvc/fs.rs |
Adds temp file write helpers for encoded content and UTF-8 BOM scripts. |
devolutions-session/src/dvc/encoding.rs |
New transcoding implementation using Win32 codepage APIs + unit tests. |
devolutions-session/Cargo.toml |
Adds Win32_Globalization Windows feature; modifies now-proto-pdu dependency config (currently broken). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [dependencies.now-proto-pdu] | ||
| optional = true | ||
| version = "0.4.2" | ||
| # TODO: wait for merge and release https://github.com/Devolutions/now-proto/pull/62 | ||
| features = ["std"] | ||
|
|
| let valid_end = find_valid_utf8_end(&input); | ||
|
|
||
| if valid_end == 0 { | ||
| // All bytes are part of an incomplete sequence. | ||
| self.leftover = input.into_owned(); | ||
| return Cow::Owned(Vec::new()); | ||
| } | ||
|
|
||
| // Save any trailing incomplete UTF-8 bytes. | ||
| if valid_end < input.len() { | ||
| self.leftover = input[valid_end..].to_vec(); | ||
| } | ||
|
|
||
| let utf8_str = match std::str::from_utf8(&input[..valid_end]) { |
| /// Returns `Err` if the input contains an incomplete multi-byte character. | ||
| fn convert_to_utf8(codepage: u32, data: &[u8]) -> Result<Vec<u8>, ()> { | ||
| if data.is_empty() { | ||
| return Ok(Vec::new()); | ||
| } | ||
|
|
||
| // First pass: get required buffer size for UTF-16 conversion. | ||
| // Using MB_ERR_INVALID_CHARS to detect incomplete sequences. | ||
| // SAFETY: `data` is a valid byte slice. |
This PR adds redirected IO text transcoding to/from OEM code page.
By default all windows command shells (cmd, PowerShell5 & PowerShell7) use OEM code page for console input/output. In RDM we expect UTF-8, and prior to Devolutions/now-proto#62 wire format for now proto was not specified. This PR changes this ad implements OEM <-> UTF8 transcoding.
Additionally,
UNICODE_CONSOLEflag was implemented, enabling explicit switching to UTF-8 stdio mode in cmd, ps, pwsh by injecting encoding change command to script file. That means, not only OEM encoding is now handled correctly, but any unicode text can be correctly transfered to/from exec session and displayed in RDM.Merge blocked by Devolutions/now-proto#62 (crate release)
Issue: DGW-370