Skip to content

Commit f3df96f

Browse files
fix(windows): binary patching 32 bit updater type (#14065)
* fix(windows): binary patching 32 bit updater type * Use `get` instead of size check and then assert
1 parent c0d3f9d commit f3df96f

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

.changes/binary-patching-32-bit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": "patch:bug"
3+
---
4+
5+
Fix binary patching updater type fails on 32 bit Windows builds

crates/tauri-bundler/src/bundle/windows/util.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ pub fn patch_binary(binary_path: &PathBuf, package_type: &crate::PackageType) ->
100100
.ok_or(crate::Error::MissingBundleTypeVar)?;
101101

102102
let data_offset = tauri_bundle_section.pointer_to_raw_data as usize;
103-
104-
if data_offset + 8 > file_data.len() {
105-
return Err(crate::Error::BinaryOffsetOutOfRange);
106-
}
107-
108-
let ptr_bytes = &file_data[data_offset..data_offset + 8];
109-
let ptr_value = u64::from_le_bytes(ptr_bytes.try_into().map_err(|_| {
110-
crate::Error::BinaryParseError(
111-
std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid pointer bytes").into(),
112-
)
113-
})?);
103+
let pointer_size = if pe.is_64 { 8 } else { 4 };
104+
let ptr_bytes = file_data
105+
.get(data_offset..data_offset + pointer_size)
106+
.ok_or(crate::Error::BinaryOffsetOutOfRange)?;
107+
// `try_into` is safe to `unwrap` here because we have already checked the slice's size through `get`
108+
let ptr_value = if pe.is_64 {
109+
u64::from_le_bytes(ptr_bytes.try_into().unwrap())
110+
} else {
111+
u32::from_le_bytes(ptr_bytes.try_into().unwrap()).into()
112+
};
114113

115114
let rdata_section = pe
116115
.sections
@@ -133,12 +132,10 @@ pub fn patch_binary(binary_path: &PathBuf, package_type: &crate::PackageType) ->
133132
let file_offset = rdata_section.pointer_to_raw_data as usize
134133
+ (rva as usize).saturating_sub(rdata_section.virtual_address as usize);
135134

136-
if file_offset + 3 > file_data.len() {
137-
return Err(crate::Error::BinaryOffsetOutOfRange);
138-
}
139-
140135
// Overwrite the string at that offset
141-
let string_bytes = &mut file_data[file_offset..file_offset + 3];
136+
let string_bytes = file_data
137+
.get_mut(file_offset..file_offset + 3)
138+
.ok_or(crate::Error::BinaryOffsetOutOfRange)?;
142139
match package_type {
143140
crate::PackageType::Nsis => string_bytes.copy_from_slice(b"NSS"),
144141
crate::PackageType::WindowsMsi => string_bytes.copy_from_slice(b"MSI"),

0 commit comments

Comments
 (0)