diff --git a/src/legacy/shrink.rs b/src/legacy/shrink.rs index 769601ac2..5c08e8ea1 100644 --- a/src/legacy/shrink.rs +++ b/src/legacy/shrink.rs @@ -115,21 +115,22 @@ fn read_code( code_size: &mut u8, codetab: &mut [Codetab], queue: &mut CodeQueue, -) -> io::Result { +) -> io::Result> { // assert(sizeof(code) * CHAR_BIT >= *code_size); let code = is.read::(*code_size as u32)?; // Handle regular codes (the common case). if code != CONTROL_CODE as u16 { - return Ok(code); + return Ok(Some(code)); } // Handle control codes. - let control_code = is.read::(*code_size as u32)?; - if control_code == INC_CODE_SIZE { - if *code_size >= MAX_CODE_SIZE { - return Err(io::Error::new(ErrorKind::InvalidData, "tried to increase code size when already at maximum)); - } + let control_code = if let Ok(c) = is.read::(*code_size as u32) { + c + } else { + return Ok(None); + }; + if control_code == INC_CODE_SIZE && *code_size < MAX_CODE_SIZE { (*code_size) += 1; return read_code(is, code_size, codetab, queue); } @@ -137,7 +138,7 @@ fn read_code( unshrink_partial_clear(codetab, queue); return read_code(is, code_size, codetab, queue); } - Err(io::Error::new(ErrorKind::InvalidData, format!("Invalid control code {}", control_code))) + return Ok(None); } /// Output the string represented by a code into dst at dst_pos. Returns