Skip to content

Commit 5ecc633

Browse files
authored
Avoid transforming array parameters with mismatched metadata (#2037)
1 parent 6d45cc6 commit 5ecc633

File tree

97 files changed

+1867
-1352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1867
-1352
lines changed

crates/libs/metadata/src/reader/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub enum ArrayInfo {
4848
RelativeByteLen(usize),
4949
RelativePtr(usize),
5050
None,
51-
Removed,
5251
}
5352

5453
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
@@ -542,6 +541,15 @@ impl<'a> Reader<'a> {
542541
})
543542
.collect();
544543

544+
// Remove any byte arrays that aren't byte-sized types.
545+
for param in &mut params {
546+
if let ArrayInfo::RelativeByteLen(_) = param.array_info {
547+
if !param.ty.is_byte_size() {
548+
param.array_info = ArrayInfo::None
549+
}
550+
}
551+
}
552+
545553
for position in 0..params.len() {
546554
// Point len params back to the corresponding ptr params.
547555
match params[position].array_info {
@@ -550,12 +558,12 @@ impl<'a> Reader<'a> {
550558
if !self.param_flags(params[relative].def).output() && position != relative && !params[relative].ty.is_pointer() {
551559
params[relative].array_info = ArrayInfo::RelativePtr(position);
552560
} else {
553-
params[position].array_info = ArrayInfo::Removed;
561+
params[position].array_info = ArrayInfo::None;
554562
}
555563
}
556564
ArrayInfo::Fixed(_) => {
557565
if self.param_free_with(params[position].def).is_some() {
558-
params[position].array_info = ArrayInfo::Removed;
566+
params[position].array_info = ArrayInfo::None;
559567
}
560568
}
561569
_ => {}
@@ -577,9 +585,9 @@ impl<'a> Reader<'a> {
577585
// Remove all sets.
578586
for (len, ptrs) in sets {
579587
if ptrs.len() > 1 {
580-
params[len].array_info = ArrayInfo::Removed;
588+
params[len].array_info = ArrayInfo::None;
581589
for ptr in ptrs {
582-
params[ptr].array_info = ArrayInfo::Removed;
590+
params[ptr].array_info = ArrayInfo::None;
583591
}
584592
}
585593
}

crates/libs/metadata/src/reader/type.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,18 @@ impl Type {
127127
/// Returns `true` if the `Type` is incomplete.
128128
pub fn is_void(&self) -> bool {
129129
match self {
130-
// TODO: do we care about void behind pointers?
131130
Type::ConstPtr((kind, _)) | Type::MutPtr((kind, _)) => kind.is_void(),
132131
Type::Void => true,
133132
_ => false,
134133
}
135134
}
135+
136+
/// Returns `true` if the `Type` has a byte-sized address.
137+
pub fn is_byte_size(&self) -> bool {
138+
match self {
139+
Type::ConstPtr((kind, _)) | Type::MutPtr((kind, _)) => kind.is_byte_size(),
140+
Type::I8 | Type::U8 | Type::Void | Type::PSTR | Type::PCSTR => true,
141+
_ => false,
142+
}
143+
}
136144
}

crates/libs/windows/src/Windows/Win32/Data/RightsManagement/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ where
258258
extern "system" {
259259
fn DRMCreateRight(wszrightname: ::windows::core::PCWSTR, pstfrom: *mut super::super::Foundation::SYSTEMTIME, pstuntil: *mut super::super::Foundation::SYSTEMTIME, cextendedinfo: u32, pwszextendedinfoname: *const ::windows::core::PWSTR, pwszextendedinfovalue: *const ::windows::core::PWSTR, phright: *mut u32) -> ::windows::core::HRESULT;
260260
}
261-
DRMCreateRight(wszrightname.into(), ::core::mem::transmute(pstfrom), ::core::mem::transmute(pstuntil), ::core::mem::transmute(cextendedinfo), ::core::mem::transmute(pwszextendedinfoname.unwrap_or(::std::ptr::null())), ::core::mem::transmute(pwszextendedinfovalue.unwrap_or(::std::ptr::null())), ::core::mem::transmute(phright)).ok()
261+
DRMCreateRight(wszrightname.into(), ::core::mem::transmute(pstfrom), ::core::mem::transmute(pstuntil), cextendedinfo, ::core::mem::transmute(pwszextendedinfoname.unwrap_or(::std::ptr::null())), ::core::mem::transmute(pwszextendedinfovalue.unwrap_or(::std::ptr::null())), ::core::mem::transmute(phright)).ok()
262262
}
263263
#[doc = "*Required features: `\"Win32_Data_RightsManagement\"`*"]
264264
#[inline]

crates/libs/windows/src/Windows/Win32/Devices/Communication/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ where
269269
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
270270
#[cfg(feature = "Win32_Foundation")]
271271
#[inline]
272-
pub unsafe fn SetCommConfig<'a, P0>(hcommdev: P0, lpcc: &[u8]) -> super::super::Foundation::BOOL
272+
pub unsafe fn SetCommConfig<'a, P0>(hcommdev: P0, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL
273273
where
274274
P0: ::std::convert::Into<super::super::Foundation::HANDLE>,
275275
{
276276
#[cfg_attr(windows, link(name = "windows"))]
277277
extern "system" {
278278
fn SetCommConfig(hcommdev: super::super::Foundation::HANDLE, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL;
279279
}
280-
SetCommConfig(hcommdev.into(), ::core::mem::transmute(lpcc.as_ptr()), lpcc.len() as _)
280+
SetCommConfig(hcommdev.into(), ::core::mem::transmute(lpcc), dwsize)
281281
}
282282
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
283283
#[cfg(feature = "Win32_Foundation")]
@@ -321,28 +321,28 @@ where
321321
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
322322
#[cfg(feature = "Win32_Foundation")]
323323
#[inline]
324-
pub unsafe fn SetDefaultCommConfigA<'a, P0>(lpszname: P0, lpcc: &[u8]) -> super::super::Foundation::BOOL
324+
pub unsafe fn SetDefaultCommConfigA<'a, P0>(lpszname: P0, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL
325325
where
326326
P0: ::std::convert::Into<::windows::core::PCSTR>,
327327
{
328328
#[cfg_attr(windows, link(name = "windows"))]
329329
extern "system" {
330330
fn SetDefaultCommConfigA(lpszname: ::windows::core::PCSTR, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL;
331331
}
332-
SetDefaultCommConfigA(lpszname.into(), ::core::mem::transmute(lpcc.as_ptr()), lpcc.len() as _)
332+
SetDefaultCommConfigA(lpszname.into(), ::core::mem::transmute(lpcc), dwsize)
333333
}
334334
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
335335
#[cfg(feature = "Win32_Foundation")]
336336
#[inline]
337-
pub unsafe fn SetDefaultCommConfigW<'a, P0>(lpszname: P0, lpcc: &[u8]) -> super::super::Foundation::BOOL
337+
pub unsafe fn SetDefaultCommConfigW<'a, P0>(lpszname: P0, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL
338338
where
339339
P0: ::std::convert::Into<::windows::core::PCWSTR>,
340340
{
341341
#[cfg_attr(windows, link(name = "windows"))]
342342
extern "system" {
343343
fn SetDefaultCommConfigW(lpszname: ::windows::core::PCWSTR, lpcc: *const COMMCONFIG, dwsize: u32) -> super::super::Foundation::BOOL;
344344
}
345-
SetDefaultCommConfigW(lpszname.into(), ::core::mem::transmute(lpcc.as_ptr()), lpcc.len() as _)
345+
SetDefaultCommConfigW(lpszname.into(), ::core::mem::transmute(lpcc), dwsize)
346346
}
347347
#[doc = "*Required features: `\"Win32_Devices_Communication\"`, `\"Win32_Foundation\"`*"]
348348
#[cfg(feature = "Win32_Foundation")]

0 commit comments

Comments
 (0)