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> {