Linux C/C++ Crash: SIGBUS (Bus Error) on `mmap()` File Access

Accessed a memory-mapped page beyond the truncated underlying file size or unaligned hardware address.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: Linux C/C++ Crash Platform: C/C++
Common Root Causes:
  • Accessed a memory-mapped page beyond the truncated underlying file size or unaligned hardware address.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Extend the file with `ftruncate()` / `fallocate()` before `mmap()` and use `memcpy` for unaligned loads.
Safe Diagnostic Command:
stat -c %s <file> && gdb -batch -ex bt ./<bin> core
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Accessed a memory-mapped page beyond the truncated underlying file size or unaligned hardware address. Recommended diagnostic: `stat -c %s <file> && gdb -batch -ex bt ./<bin> core`. Remediation: Extend the file with `ftruncate()` / `fallocate()` before `mmap()` and use `memcpy` for unaligned loads.

Worked Examples

  • Run `stat -c %s <file> && gdb -batch -ex bt ./<bin> core` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-cpp-sigbus-unaligned-mmap · Independently verified: 2026-11-25

Related Resources