Skip to content

fix: correct UTF-16 string length computations#1161

Draft
Benoît Cortier (CBenoit) wants to merge 7 commits intomasterfrom
fix/rdp-string-handling
Draft

fix: correct UTF-16 string length computations#1161
Benoît Cortier (CBenoit) wants to merge 7 commits intomasterfrom
fix/rdp-string-handling

Conversation

@CBenoit
Copy link
Member

@CBenoit Benoît Cortier (CBenoit) commented Mar 10, 2026

Replace legacy string helpers in ironrdp-pdu (to_utf16_bytes, from_utf16_bytes, encode_string, decode_string, etc.) with typed primitives from the ironrdp-str crate.

This is both improving the correctness of UTF-16 string handling, and improving the performance of decoding because ironrdp-str primitives are lazily-validated as opposed to the previously eagerly-validated logic.

Fixes #130

Replace legacy string helpers in ironrdp-pdu (to_utf16_bytes,
from_utf16_bytes, encode_string, decode_string, etc.) with typed
primitives from the ironrdp-str crate:
@CBenoit
Copy link
Member Author

  • Add ironrdp-str::ansi module with free-standing helpers for ANSI
    (UTF-8) wire strings: decode_ansi, read_ansi_null_term,
    encoded_ansi_len_{with,without}null, write_ansi{with,without}_null
  • Migrate fixed-size Unicode fields (client_name, ime_file_name,
    dig_product_id, timezone names, keyboard_ime_filename, FileDescriptor
    name) to FixedString
  • Migrate length-prefixed Unicode fields (ProductInfo/LicenseInformation
    company_name/product_id, FileRenameInformation file_name) to
    CbU32StringNullIncluded
  • Migrate PreconnectionBlob v2_payload to CchPrefixedString
  • Migrate ANSI fields (scope, channel_name, source_descriptor,
    client_username, client_machine_name) to use ironrdp-str::ansi helpers
  • Remove UTF8_NULL_TERMINATOR_SIZE constant and delete utf16.rs
  • Add ironrdp-str dependency to ironrdp-cliprdr, ironrdp-connector,
    ironrdp-dvc, ironrdp-rdpdr, ironrdp-server

@CBenoit Benoît Cortier (CBenoit) changed the title fix: migrate String fields to ironrdp-str typed primitives fix: correct UTF-16 string length computations Mar 10, 2026
@CBenoit Benoît Cortier (CBenoit) enabled auto-merge (squash) March 10, 2026 16:23
@github-actions
Copy link

github-actions bot commented Mar 10, 2026

Coverage Report 🤖 ⚙️

Past:
Total lines: 37300
Covered lines: 24193 (64.86%)

New:
Total lines: 37258
Covered lines: 24217 (65.00%)

Diff: +0.14%

[this comment will be updated automatically]

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces several ad-hoc UTF-16/ANSI string helpers in ironrdp-pdu (and related crates) with typed wire-string primitives from ironrdp-str, aiming to fix incorrect UTF-16 length computations (Issue #130) and improve decode performance via lazy validation.

Changes:

  • Migrate multiple protocol fields from String + legacy helpers to ironrdp-str typed primitives (FixedString, CchString, CbU32String*) for correct UTF-16 sizing and null-terminator handling.
  • Introduce ironrdp_str::ansi free functions for UTF-8/ANSI wire string decode/encode/length computations.
  • Update tests, fixtures, and crate dependencies across the workspace to use the new string representations.

Reviewed changes

Copilot reviewed 36 out of 37 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/ironrdp-testsuite-core/tests/pcb.rs Updates PCB tests to use CchString for v2 payloads.
crates/ironrdp-testsuite-core/tests/clipboard/mod.rs Adjusts expected clipboard file list debug output for FixedString<260>.
crates/ironrdp-testsuite-core/src/core_data.rs Switches core data fixtures to FixedString fields.
crates/ironrdp-testsuite-core/src/client_info.rs Switches timezone name fixtures to FixedString<32>.
crates/ironrdp-testsuite-core/Cargo.toml Adds dependency on ironrdp-str.
crates/ironrdp-str/src/prefixed.rs Adds CbU32StringNoNull alias for u32 byte-prefixed, non-null-terminated UTF-16 strings.
crates/ironrdp-str/src/lib.rs Exposes new ansi module behind alloc.
crates/ironrdp-str/src/ansi.rs Adds ANSI (UTF-8) decode/encode and length helpers.
crates/ironrdp-str/Cargo.toml Disables lib tests/doctests for the crate.
crates/ironrdp-server/src/capabilities.rs Updates input capability construction to use FixedString IME filename.
crates/ironrdp-server/Cargo.toml Adds dependency on ironrdp-str.
crates/ironrdp-rdpdr/src/pdu/efs.rs Changes FileRenameInformation filename handling to a prefixed string type.
crates/ironrdp-rdpdr/Cargo.toml Adds dependency on ironrdp-str.
crates/ironrdp-pdu/src/utf16.rs Removes legacy UTF-16 helper module.
crates/ironrdp-pdu/src/rdp/server_license/server_upgrade_license/tests.rs Updates license upgrade tests to use CbU32StringNullIncluded.
crates/ironrdp-pdu/src/rdp/server_license/server_upgrade_license/mod.rs Reworks license info encoding/decoding with ansi + prefixed UTF-16 string types.
crates/ironrdp-pdu/src/rdp/server_license/server_license_request/tests.rs Updates license request tests to use CbU32StringNullIncluded.
crates/ironrdp-pdu/src/rdp/server_license/server_license_request/mod.rs Reworks product info and scope strings using ansi + prefixed UTF-16 string types.
crates/ironrdp-pdu/src/rdp/server_license/mod.rs Removes UTF-8/UTF-16 null terminator size constants no longer needed.
crates/ironrdp-pdu/src/rdp/server_license/client_new_license_request/tests.rs Updates size computations and product info test data to new string helpers/types.
crates/ironrdp-pdu/src/rdp/server_license/client_new_license_request/mod.rs Switches username/machine-name blob string handling to ansi helpers.
crates/ironrdp-pdu/src/rdp/client_info.rs Switches timezone names to FixedString<32> and uses typed decode/encode.
crates/ironrdp-pdu/src/rdp/capability_sets/mod.rs Uses ansi::decode_ansi for Demand Active source descriptor decoding.
crates/ironrdp-pdu/src/rdp/capability_sets/input/tests.rs Updates input capability tests for FixedString IME filename.
crates/ironrdp-pdu/src/rdp/capability_sets/input.rs Switches IME filename to FixedString<32> and typed decode/encode.
crates/ironrdp-pdu/src/pcb.rs Reworks PCB v2 payload to CchString and updates size/encode/decode accordingly.
crates/ironrdp-pdu/src/lib.rs Stops exporting removed utf16 module.
crates/ironrdp-pdu/src/gcc/core_data/client.rs Switches core data fixed-size string fields to FixedString types.
crates/ironrdp-pdu/Cargo.toml Adds dependency on ironrdp-str.
crates/ironrdp-dvc/src/pdu.rs Switches DRDYNVC channel name parsing/encoding to ansi helpers.
crates/ironrdp-dvc/Cargo.toml Adds dependency on ironrdp-str.
crates/ironrdp-connector/src/connection_activation.rs Constructs FixedString IME filename using truncating helper.
crates/ironrdp-connector/src/connection.rs Constructs FixedString client/IME/product ID fields using truncating helper.
crates/ironrdp-connector/Cargo.toml Adds dependency on ironrdp-str.
crates/ironrdp-cliprdr/src/pdu/format_data/file_list.rs Switches file descriptor name field to FixedString<260> and typed decode/encode.
crates/ironrdp-cliprdr/Cargo.toml Adds dependency on ironrdp-str.
Cargo.lock Records new workspace dependency edges on ironrdp-str.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 40 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 40 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Fix UTF-16 string length computations

2 participants