File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
33
- Fixed a missed ` flush ` call that may be causing communication errors (#521 )
34
34
- Fix "SHA-256 comparison failed: [ ...] attempting to boot anyway..." (#567 )
35
35
- Windows: Update RST/DTR order to avoid issues.
36
+ - Tolerate non-utf8 data in boot detection (#573 )
36
37
37
38
### Changed
38
39
Original file line number Diff line number Diff line change 7
7
use std:: {
8
8
io:: { BufWriter , Write } ,
9
9
iter:: zip,
10
- str:: from_utf8,
11
10
thread:: sleep,
12
11
time:: Duration ,
13
12
} ;
@@ -155,7 +154,7 @@ impl Connection {
155
154
return Ok ( ( ) ) ;
156
155
}
157
156
let mut download_mode: bool = false ;
158
- let mut boot_mode: & str = "" ;
157
+ let mut boot_mode = String :: new ( ) ;
159
158
let mut boot_log_detected = false ;
160
159
let mut buff: Vec < u8 > ;
161
160
if self . before_operation != ResetBeforeOperation :: NoReset {
@@ -173,18 +172,22 @@ impl Connection {
173
172
) ) ) ;
174
173
}
175
174
176
- let read_slice = from_utf8 ( & buff[ ..read_bytes as usize ] ) . map_err ( |err| {
177
- debug ! ( "Error: {}" , err ) ;
178
- Error :: InvalidSerialRead
179
- } ) ? ;
175
+ let read_slice = String :: from_utf8_lossy ( & buff[ ..read_bytes as usize ] ) . into_owned ( ) ;
176
+ if !read_slice . contains ( "boot" ) {
177
+ return Err ( Error :: InvalidSerialRead ) ;
178
+ }
180
179
181
180
let pattern = Regex :: new ( r"boot:(0x[0-9a-fA-F]+)(.*waiting for download)?" ) . unwrap ( ) ;
182
181
183
182
// Search for the pattern in the read data
184
- if let Some ( data) = pattern. captures ( read_slice) {
183
+ if let Some ( data) = pattern. captures ( & read_slice) {
185
184
boot_log_detected = true ;
186
185
// Boot log detected
187
- boot_mode = data. get ( 1 ) . map ( |m| m. as_str ( ) ) . unwrap_or_default ( ) ;
186
+ boot_mode = data
187
+ . get ( 1 )
188
+ . map ( |m| m. as_str ( ) )
189
+ . unwrap_or_default ( )
190
+ . to_string ( ) ;
188
191
download_mode = data. get ( 2 ) . is_some ( ) ;
189
192
190
193
// Further processing or printing the results
You can’t perform that action at this time.
0 commit comments