Skip to content

extensions/vtab: fix i32 being passed as i64 across FFI boundary#2064

Merged
penberg merged 2 commits intomainfrom
fix-misaligned-i64-across-ffi
Jul 16, 2025
Merged

extensions/vtab: fix i32 being passed as i64 across FFI boundary#2064
penberg merged 2 commits intomainfrom
fix-misaligned-i64-across-ffi

Conversation

@jussisaurio
Copy link
Collaborator

@jussisaurio jussisaurio commented Jul 12, 2025

as nilskch points out in #1807, Rust 1.88.0 is stricter about alignment checks.

because rust integers default to i32, we were casting a pointer to an i32 as a pointer to an i64 causing a panic when dereferenced due to misalignment as rust expects it to be 8 byte aligned.

as nilskch points out in #1807, Rust 1.88.0 is stricter about
alignment.

because rust integers default to `i32`, we were casting a pointer
to an `i32` as a pointer to an `i64` causing a panic when dereferenced
due to misalignment as rust expects it to be 8 byte aligned.
sql.as_ptr(),
args as *mut Value,
arg_count,
&last_insert_rowid as *const _ as *mut i64,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw let's try to avoid this as *const _ stuff, compiler would've caught this invalid cast otherwise

let arg_count = args.len() as i32;
let args = args.as_ptr();
let last_insert_rowid = 0;
let mut last_insert_rowid: i64 = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usize is the architecture specific size to use herr

@penberg penberg closed this in f72ceaf Jul 16, 2025
@penberg penberg merged commit f72ceaf into main Jul 16, 2025
52 checks passed
@penberg penberg deleted the fix-misaligned-i64-across-ffi branch July 16, 2025 05:28
jussisaurio added a commit that referenced this pull request Jul 17, 2025
This PR updates to version Rust 1.88.0 ([Release
notes](https://releases.rs/docs/1.88.0/)) and fixes all the clippy
errors that come with the new Rust version.
This is possible in the latest Rust version:
```rust
if let Some(foo) = bar && foo.is_cool() {
  ...
}
```
There are three complications in the migration (so far):
- A BUNCH of Clippy warnings (mostly fixed in
#1827)
- Windows cross compilation failed; linking `advapi32` on windows fixes
it
  - Since Rust 1.87.0, advapi32 is not linked by default anymore
([Release notes](https://github.com/rust-
lang/rust/blob/master/RELEASES.md#compatibility-notes-1),
[PR](rust-lang/rust#138233))
- Rust is more strict with FFIs and aligning pointers now. CI checks
failed with error below
  - Fixed in #2064
```
thread 'main' panicked at
core/ext/vtab_xconnect.rs:64:25:
misaligned pointer dereference: address must be
a multiple of 0x8 but is 0x7ffd9d901554
```

Closes #1807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants