From a674780bdfd792f7a38a0bbc1f592a3a8daa145e Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Sat, 22 Sep 2018 02:20:15 +0000 Subject: [PATCH] byte_buffer: fix string handling when the string is only a single null byte --- Cargo.toml | 2 +- src/byte_buffer.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3131a73..697e5fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kbinxml" -version = "0.11.2" +version = "0.11.3" authors = ["Matt Bilker "] [dependencies] diff --git a/src/byte_buffer.rs b/src/byte_buffer.rs index 2cd132d..218a3d8 100644 --- a/src/byte_buffer.rs +++ b/src/byte_buffer.rs @@ -18,7 +18,13 @@ pub(crate) fn strip_trailing_null_bytes<'a>(data: &'a [u8]) -> &'a [u8] { while index > 0 && index < len && data[index] == 0x00 { index -= 1; } - &data[..=index] + + // Handle case where the buffer is only a null byte + if index == 0 && data.len() == 1 && data[index] == 0x00 { + &[] + } else { + &data[..=index] + } } pub struct ByteBufferRead {