From 7dc139737c692d341fc3ab1fe78d1fb88b4ac669 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 15 Dec 2022 17:03:12 +0100 Subject: [PATCH] fix substraction overflow --- Cargo.toml | 2 +- src/switch64.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b7ae83..8728231 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "nettext" description = "A text-based data format for cryptographic network protocols" authors = ["Alex Auvolat "] -version = "0.3.2" +version = "0.3.3" edition = "2021" license = "AGPL-3.0" readme = "README.md" diff --git a/src/switch64.rs b/src/switch64.rs index 8d47629..0c6a4da 100644 --- a/src/switch64.rs +++ b/src/switch64.rs @@ -32,7 +32,10 @@ pub fn encode(bytes: &[u8], allow_whitespace: bool) -> Vec { // We stop at the first position where we find three consecutive // characters to encode as-is let mut b64end = bytes.len(); - for i in pos..bytes.len() - 3 { + for i in pos..bytes.len() { + if i + 3 > bytes.len() { + break; + } if bytes[i..i + 3] .iter() .all(|c| is_valid_plaintext_char(*c, allow_whitespace))