From 4e71885fd1fcaefe04ed2f8384c4a8b1fcc9d05d Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Tue, 18 Dec 2018 22:02:08 +0000 Subject: [PATCH] text_reader: add trailing null byte to the end of attribute strings --- src/text_reader.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/text_reader.rs b/src/text_reader.rs index a16cbbd..067c12d 100644 --- a/src/text_reader.rs +++ b/src/text_reader.rs @@ -40,6 +40,12 @@ impl<'a> TextXmlReader<'a> { } fn parse_attribute(&self, key: &[u8], value: &[u8]) -> Result { + let mut value = BytesMut::from(value.to_vec()); + + // Add the trailing null byte that kbin has at the end of strings + value.reserve(1); + value.put_u8(0); + // `Attribute` nodes do not have the `is_array` flag set let node_type = (StandardType::Attribute, false); let data = NodeData::Some { @@ -47,7 +53,7 @@ impl<'a> TextXmlReader<'a> { encoding: self.encoding, data: Bytes::from(key), }, - value_data: Bytes::from(value), + value_data: value.freeze(), }; Ok(NodeDefinition::with_data(self.encoding, node_type, data))