Skip to content

Bug: RustBuffer uses size_t instead of uint64_t, causing crashes on 32-bit ARM #314

@sfourdrinier

Description

@sfourdrinier

Bug Report

Description

The generated RustBuffer struct in cpp/includes/RustBuffer.h uses size_t for the capacity and len fields, but UniFFI's C ABI specification requires uint64_t on all platforms. This causes a critical ABI mismatch on 32-bit ARM architectures.

Platforms Affected

  • 32-bit ARM (armeabi-v7a): Crashes immediately during argument marshalling
  • 64-bit platforms: Works by accident (size_t == uint64_t == 8 bytes)

Reproduction

  1. Build a React Native app using uniffi-bindgen-react-native on a 32-bit ARM device (e.g., Amazon Fire TV, armeabi-v7a)
  2. Call any UniFFI function that accepts a RustBuffer parameter
  3. App crashes with SIGSEGV before any Rust code executes

Crash Details

Process: <app>, PID: <pid>
Signal: SIGSEGV (Segmentation fault)

#00 pc <addr> <lib>.so (NativeModule::cpp_uniffi_<crate>_fn_constructor_<type>_new+102)

The crash occurs in the C++ JSI wrapper during constructor marshalling. The stack/register corruption happens because:

  • C++ passes RustBuffer with 4-byte size_t fields on 32-bit ARM
  • Rust expects RustBuffer with 8-byte u64 fields per UniFFI spec

Root Cause

The RustBuffer struct definition doesn't match UniFFI's ABI:

// Current (incorrect) - cpp/includes/RustBuffer.h
struct RustBuffer {
  size_t capacity;  // 4 bytes on 32-bit ARM, 8 bytes on 64-bit
  size_t len;       // 4 bytes on 32-bit ARM, 8 bytes on 64-bit
  uint8_t *data;
};

UniFFI's ABI specification mandates uint64_t (8 bytes) on ALL platforms:

Fix

Change size_t to uint64_t to match UniFFI's ABI across all platforms.

PR submitted: #313

Environment

  • Device: Amazon Fire TV (armeabi-v7a)
  • Framework: Expo SDK 54 / React Native 0.81
  • uniffi-bindgen-react-native: latest from main branch

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions