mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:17:02 +00:00
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
This commit is contained in:
parent
c0d3f9d47e
commit
f3df96fb38
5
.changes/binary-patching-32-bit.md
Normal file
5
.changes/binary-patching-32-bit.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-bundler": "patch:bug"
|
||||
---
|
||||
|
||||
Fix binary patching updater type fails on 32 bit Windows builds
|
||||
@ -100,17 +100,16 @@ pub fn patch_binary(binary_path: &PathBuf, package_type: &crate::PackageType) ->
|
||||
.ok_or(crate::Error::MissingBundleTypeVar)?;
|
||||
|
||||
let data_offset = tauri_bundle_section.pointer_to_raw_data as usize;
|
||||
|
||||
if data_offset + 8 > file_data.len() {
|
||||
return Err(crate::Error::BinaryOffsetOutOfRange);
|
||||
}
|
||||
|
||||
let ptr_bytes = &file_data[data_offset..data_offset + 8];
|
||||
let ptr_value = u64::from_le_bytes(ptr_bytes.try_into().map_err(|_| {
|
||||
crate::Error::BinaryParseError(
|
||||
std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid pointer bytes").into(),
|
||||
)
|
||||
})?);
|
||||
let pointer_size = if pe.is_64 { 8 } else { 4 };
|
||||
let ptr_bytes = file_data
|
||||
.get(data_offset..data_offset + pointer_size)
|
||||
.ok_or(crate::Error::BinaryOffsetOutOfRange)?;
|
||||
// `try_into` is safe to `unwrap` here because we have already checked the slice's size through `get`
|
||||
let ptr_value = if pe.is_64 {
|
||||
u64::from_le_bytes(ptr_bytes.try_into().unwrap())
|
||||
} else {
|
||||
u32::from_le_bytes(ptr_bytes.try_into().unwrap()).into()
|
||||
};
|
||||
|
||||
let rdata_section = pe
|
||||
.sections
|
||||
@ -133,12 +132,10 @@ pub fn patch_binary(binary_path: &PathBuf, package_type: &crate::PackageType) ->
|
||||
let file_offset = rdata_section.pointer_to_raw_data as usize
|
||||
+ (rva as usize).saturating_sub(rdata_section.virtual_address as usize);
|
||||
|
||||
if file_offset + 3 > file_data.len() {
|
||||
return Err(crate::Error::BinaryOffsetOutOfRange);
|
||||
}
|
||||
|
||||
// Overwrite the string at that offset
|
||||
let string_bytes = &mut file_data[file_offset..file_offset + 3];
|
||||
let string_bytes = file_data
|
||||
.get_mut(file_offset..file_offset + 3)
|
||||
.ok_or(crate::Error::BinaryOffsetOutOfRange)?;
|
||||
match package_type {
|
||||
crate::PackageType::Nsis => string_bytes.copy_from_slice(b"NSS"),
|
||||
crate::PackageType::WindowsMsi => string_bytes.copy_from_slice(b"MSI"),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user