Skip to content

Commit 5ad0884

Browse files
Merge pull request #1576 from kanru-contrib/push-zmxoqnnswzvm
On Windows handle invalid UTF-8 from SMBIOS
2 parents 6ed52f2 + 3c90fe6 commit 5ad0884

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/windows/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ cfg_if! {
136136
let info: T = unsafe { std::ptr::read_unaligned(table[i..].as_ptr() as *const _) };
137137

138138
// As said in the SMBIOS 3 standard: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.6.0.pdf,
139-
// the strings are necessarily in UTF-8.
139+
// the strings are necessarily in UTF-8. But sometimes virtual machines may return non-compliant data.
140140
let values = table[(i + info.length() as usize)..]
141141
.split(|&b| b == 0)
142-
.map(|s| unsafe { std::str::from_utf8_unchecked(s) })
142+
.filter_map(|s| std::str::from_utf8(s).ok())
143143
.take_while(|s| !s.is_empty())
144144
.collect();
145145

0 commit comments

Comments
 (0)