From 8857c3c25ea40bd2a2f4d850f67b16b2306393c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Thu, 11 May 2023 17:36:05 -0400 Subject: [PATCH] docs: comment on string_len in client_info module Comment says it all. This code should be fixed at some point. --- crates/ironrdp-pdu/src/rdp/client_info.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/ironrdp-pdu/src/rdp/client_info.rs b/crates/ironrdp-pdu/src/rdp/client_info.rs index e1d889af..d2bafd71 100644 --- a/crates/ironrdp-pdu/src/rdp/client_info.rs +++ b/crates/ironrdp-pdu/src/rdp/client_info.rs @@ -570,5 +570,12 @@ pub enum ClientInfoError { } fn string_len(value: &str, character_set: CharacterSet) -> u16 { + // FIXME: this is not the right way to compute the number of bytes for unicode strings. + // This is a time bomb: both UTF-8 and UTF-16 are using a variable-length encoding and code points may be encoded + // using multiple code units. The thing is, UTF-16 uses one or two 16-bit code units and + // UTF-8 uses between one and four 8-bit code units. It’s really not always the case that a code point + // in UTF-16 is twice as big as the same code point in UTF-8. + // Refer to `ironrdp_pdu::pcb` module for a correct implementation. + // Something like that: value.encode_utf16().count() * 2 (+2 if we need to insert a null terminator: 0x0000) value.len() as u16 * character_set.to_u16().unwrap() }