Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix a crash with Connection module when connecting to a loopback serial port (#954)

### Removed

## [4.1.0] - 2025-09-18
Expand Down
29 changes: 11 additions & 18 deletions espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,31 +397,24 @@ impl Connection {

let value = match response.len() {
10 | 12 => CommandResponseValue::ValueU32(u32::from_le_bytes(
response[4..][..4].try_into().unwrap(),
response[4..][..4].try_into()?,
)),
// MD5 is in ASCII
44 => CommandResponseValue::ValueU128(u128::from_str_radix(
std::str::from_utf8(&response[8..][..32])?,
16,
)?),
// MD5 is BE bytes
26 => CommandResponseValue::ValueU128(u128::from_be_bytes(
response[8..][..16].try_into()?,
)),
44 => {
// MD5 is in ASCII
CommandResponseValue::ValueU128(
u128::from_str_radix(
std::str::from_utf8(&response[8..][..32]).unwrap(),
16,
)
.unwrap(),
)
}
26 => {
// MD5 is BE bytes
CommandResponseValue::ValueU128(u128::from_be_bytes(
response[8..][..16].try_into().unwrap(),
))
}
_ => CommandResponseValue::Vector(response.clone()),
};

let header = CommandResponse {
resp: response[0],
return_op: response[1],
return_length: u16::from_le_bytes(response[2..][..2].try_into().unwrap()),
return_length: u16::from_le_bytes(response[2..][..2].try_into()?),
value,
error: response[response.len() - status_len + 1],
status: response[response.len() - status_len],
Expand Down
22 changes: 21 additions & 1 deletion espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[cfg(feature = "serialport")]
use std::fmt::{Display, Formatter};
use std::{array::TryFromSliceError, io};
use std::{array::TryFromSliceError, io, num::ParseIntError, str::Utf8Error};

use miette::Diagnostic;
#[cfg(feature = "serialport")]
Expand Down Expand Up @@ -294,6 +294,14 @@ pub enum Error {
#[error(transparent)]
TryFromSlice(CoreError),

/// Error while trying to parse int from text
#[error(transparent)]
ParseIntError(CoreError),

/// Error while trying to parse UTF-8 from bytes
#[error(transparent)]
Utf8Error(CoreError),

/// Failed to open file
#[error("Failed to open file: {0}")]
FileOpenError(String, #[source] io::Error),
Expand Down Expand Up @@ -380,6 +388,18 @@ impl From<TryFromSliceError> for Error {
}
}

impl From<ParseIntError> for Error {
fn from(err: ParseIntError) -> Self {
Self::ParseIntError(Box::new(err))
}
}

impl From<Utf8Error> for Error {
fn from(err: Utf8Error) -> Self {
Self::Utf8Error(Box::new(err))
}
}

impl From<object::Error> for Error {
fn from(err: object::Error) -> Self {
Self::InvalidElf(err.into())
Expand Down
4 changes: 2 additions & 2 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,8 @@ impl Flasher {
{
let metadata = image_format.metadata();
if metadata.contains_key("app_size") && metadata.contains_key("part_size") {
let app_size = metadata["app_size"].parse::<u32>().unwrap();
let part_size = metadata["part_size"].parse::<u32>().unwrap();
let app_size = metadata["app_size"].parse::<u32>()?;
let part_size = metadata["part_size"].parse::<u32>()?;

crate::cli::display_image_size(app_size, Some(part_size));
}
Expand Down
Loading