From d894e27dfad14ec3b76e39e99dbb4fd00552a1dc Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Fri, 28 Apr 2017 10:01:04 +0300 Subject: [PATCH] Fix subslicing with bad indices in `Encoder::encode_from_utf16`. Due to an oversight, it lacked the fix that `Encoder::encode_from_utf8` already had. --- README.md | 7 +++++++ src/lib.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 529a333..7498ee7 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,13 @@ encoding_rs is ## Release Notes +### 0.6.2 + +* Fix a panic from subslicing with bad indices in + `Encoder::encode_from_utf16`. (Due to an oversight, it lacked the fix that + `Encoder::encode_from_utf8` already had.) +* Micro-optimize error status accumulation in non-streaming case. + ### 0.6.1 * Avoid panic near integer overflow in a case that's unlikely to actually diff --git a/src/lib.rs b/src/lib.rs index 4f26ae9..977f94d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3718,6 +3718,12 @@ impl Encoder { // ASCII or the Roman state. We are allowed to generate any // printable ASCII excluding \ and ~. total_written += write_ncr(unmappable, &mut dst[total_written..]); + if total_written >= effective_dst_len { + return (CoderResult::OutputFull, + total_read, + total_written, + had_unmappables); + } } } }