From 100c4a189f35feb66cd4eb89fdc04087891345d6 Mon Sep 17 00:00:00 2001 From: spuds <71292624+bananaturtlesandwich@users.noreply.github.com> Date: Wed, 11 Jan 2023 13:02:44 +0000 Subject: [PATCH] remove null byte from string --- src/ext.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ext.rs b/src/ext.rs index afc7c78..09f72bf 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -38,7 +38,7 @@ impl ReadExt for R { } fn read_string(&mut self) -> Result { - Ok(match self.read_i32::()? { + let mut buf = match self.read_i32::()? { size if size.is_negative() => { let mut buf = Vec::with_capacity(-size as usize); for _ in 0..buf.capacity() { @@ -47,7 +47,10 @@ impl ReadExt for R { String::from_utf16(&buf)? } size => String::from_utf8(self.read_len(size as usize)?)?, - }) + }; + // remove the null byte + buf.pop(); + Ok(buf) } fn read_len(&mut self, len: usize) -> Result, super::Error> {