Skip to content

Harden allocation size checks#71

Merged
falseywinchnet merged 1 commit into
mainfrom
7rn4r3-main/review-core-library-for-bugs-and-vulnerabilities
Jun 27, 2026
Merged

Harden allocation size checks#71
falseywinchnet merged 1 commit into
mainfrom
7rn4r3-main/review-core-library-for-bugs-and-vulnerabilities

Conversation

@falseywinchnet

Copy link
Copy Markdown
Owner

Motivation

  • Prevent size_t arithmetic overflow in heap growth and aligned allocation paths that could produce oversized allocations or wraparound on 64-bit/32-bit hosts.
  • Avoid integer/cast overflows and out-of-range indexing in STFT plan creation where long long/int casts and buffer-size math are used.
  • Ensure C API surfaces allocation failures via bfft_status instead of letting C++ exceptions escape into C callers.

Description

  • In src/detail/bruun_kernel.hpp the heap_array::push_back growth logic now computes a safe new_cap and returns false when doubling would overflow, replacing the unchecked cap_ * 2 path.
  • In src/detail/bruun_kernel.hpp the aligned_alloc_raw routine now checks for sizeof(T) * count overflow and guards the padding addition against overflow before calling posix_memalign/_aligned_malloc.
  • In src/stft.cpp added add_overflows_size and mul_overflows_size helpers and several precondition checks (bounds against long long/int limits and addition/multiplication overflow) in bfft_stft_plan_create to reject pathological inputs.
  • In src/stft.cpp plan/vector allocation and setup are wrapped in a try block so std::bad_alloc maps to BFFT_ERROR_ALLOCATION and other exceptions map to BFFT_ERROR_INTERNAL, preserving the C ABI semantics.

Testing

  • Ran make test which built the library and executed tests/correctness and tests/api_c, and both reported success.
  • Ran the stricter build/check make check-cxx17 (with -Werror) which completed successfully.
  • No test failures observed after the changes.

Codex Task

@falseywinchnet falseywinchnet merged commit 6314da4 into main Jun 27, 2026
4 checks passed
@falseywinchnet falseywinchnet deleted the 7rn4r3-main/review-core-library-for-bugs-and-vulnerabilities branch June 27, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant