From 9a2f21160115573f02706c9b8854c7f391b6c95a Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 12 Jul 2022 20:02:54 +0100 Subject: [PATCH 1/2] Fix the known unsoundness in bevy_mikktspace --- crates/bevy_mikktspace/src/generated.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/bevy_mikktspace/src/generated.rs b/crates/bevy_mikktspace/src/generated.rs index c05b8c1566ee3..c3661a0c891b4 100644 --- a/crates/bevy_mikktspace/src/generated.rs +++ b/crates/bevy_mikktspace/src/generated.rs @@ -1503,9 +1503,7 @@ unsafe fn GenerateSharedVerticesIndexList( vP_1.z }; let iCell_0 = FindGridCell(fMin, fMax, fVal_0); - let mut pTable: *mut i32 = 0 as *mut i32; - pTable = &mut piHashTable[piHashOffsets[iCell_0] as usize] as *mut i32; - *pTable.offset(piHashCount2[iCell_0] as isize) = i as i32; + piHashTable[(piHashOffsets[iCell_0] + piHashCount2[iCell_0]) as usize] = i as i32; piHashCount2[iCell_0] += 1; i += 1 } @@ -1525,7 +1523,7 @@ unsafe fn GenerateSharedVerticesIndexList( k = 0; while k < g_iCells { // extract table of cell k and amount of entries in it - let mut pTable_0 = &mut piHashTable[piHashOffsets[k] as usize] as *mut i32; + let pTable_0 = piHashTable.as_mut_ptr().offset(piHashOffsets[k] as isize); let iEntries = piHashCount[k] as usize; if !(iEntries < 2) { e = 0; From f367a69e217030fec305203591cef7820a9d8716 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 12 Jul 2022 20:10:24 +0100 Subject: [PATCH 2/2] Fix the other place where I know there's UB --- crates/bevy_mikktspace/src/generated.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_mikktspace/src/generated.rs b/crates/bevy_mikktspace/src/generated.rs index c3661a0c891b4..c1586235da489 100644 --- a/crates/bevy_mikktspace/src/generated.rs +++ b/crates/bevy_mikktspace/src/generated.rs @@ -1060,8 +1060,8 @@ unsafe fn InitTriInfo( let mut bChooseOrientFirstTri: bool = false; if (*pTriInfos.offset((t + 1) as isize)).iFlag & 4i32 != 0i32 { bChooseOrientFirstTri = true - } else if CalcTexArea(geometry, &*piTriListIn.offset((t * 3 + 0) as isize)) - >= CalcTexArea(geometry, &*piTriListIn.offset(((t + 1) * 3 + 0) as isize)) + } else if CalcTexArea(geometry, piTriListIn.offset((t * 3 + 0) as isize)) + >= CalcTexArea(geometry, piTriListIn.offset(((t + 1) * 3 + 0) as isize)) { bChooseOrientFirstTri = true }