treat Utf8Error::valid_up_to as an offset form self.pos, which it is (#2374)

This commit is contained in:
Mark Thom
2024-04-03 15:29:29 -06:00
parent ea9e24f214
commit aab6567750

View File

@@ -192,7 +192,7 @@ impl<R: Read> CharRead for CharReader<R> {
} else if self.pos >= self.buf.len() {
return None;
} else if self.buf.len() - self.pos >= 4 && self.pos < e.valid_up_to() {
return match str::from_utf8(&self.buf[self.pos..e.valid_up_to()]) {
return match str::from_utf8(&self.buf[self.pos..self.pos + e.valid_up_to()]) {
Ok(s) => {
let mut chars = s.chars();
let c = chars.next().unwrap();
@@ -200,7 +200,7 @@ impl<R: Read> CharRead for CharReader<R> {
Some(Ok(c))
}
Err(e) => {
let badbytes = self.buf[self.pos..e.valid_up_to()].to_vec();
let badbytes = self.buf[self.pos..self.pos + e.valid_up_to()].to_vec();
Some(Err(io::Error::new(
io::ErrorKind::InvalidData,