Skip to content

Conversation

@dmazzella
Copy link
Owner

Summary

This PR includes comprehensive security fixes, JavaScript API improvements, and cross-platform compatibility enhancements for node-ctypes.

Security Fixes (C++)

  • Buffer overflow: Fixed 64-byte static buffer → std::vector in Callback
  • Race conditions: Fixed ThreadSafeCallback cleanup synchronization
  • Integer overflow: Fixed size conversions (uint32_tsize_t)
  • Memory leak: Fixed errcheck_callback_ cleanup
  • Error handling: Added proper checks for memory allocation failures

JavaScript API Improvements

  • Type system cleanup: Removed CTypeString type (no more string literals like "int32")
  • Exports cleanup: Removed types object export (only SimpleCData classes exported)
  • Memory management: Added LRU cache for CDLL to prevent unbounded growth
  • Type definitions: Updated AnyType to CType | SimpleCDataConstructor
  • Input validation: Added validation for empty field names, buffer bounds, etc.

Cross-Platform Fixes (libffi_cmake)

  • POSIX compatibility: Conditional HAVE_MKOSTEMP for FreeBSD/OpenBSD/Solaris
  • Windows ARM32: Added armasm preprocessing support
  • Platform detection: Added Android, FreeBSD, NetBSD, OpenBSD
  • ARM variants: Added armv5l, armv6l, armv7l, armv7hf support
  • macOS x64: Fixed FFI_MMAP_EXEC_WRIT definition in template

Documentation

  • Updated README with accurate API documentation
  • Clarified struct property access patterns (direct vs .get()/.set())
  • Documented packed: true option for packed structs
  • Added comprehensive limitations section

Test Plan

  • All existing tests pass (111 tests)
  • New validation tests added
  • CI/CD pipeline validation (this PR)

Breaking Changes

None - the changes remove internal/undocumented features only.

🤖 Generated with Claude Code

Security Fixes (C++):
- Fix buffer overflow in Callback (64-byte → std::vector)
- Fix race conditions in ThreadSafeCallback cleanup
- Fix integer overflow in size conversions (uint32_t → size_t)
- Fix memory leak in errcheck_callback_
- Add proper error handling for memory allocation failures

JavaScript API Improvements:
- Remove CTypeString type (no more string literals like "int32")
- Remove types object export (only SimpleCData classes exported)
- Add LRU cache for CDLL to prevent memory leaks
- Update AnyType to: CType | SimpleCDataConstructor
- Add input validation (empty field names, buffer bounds, etc.)

Cross-Platform Fixes (libffi_cmake):
- Add conditional HAVE_MKOSTEMP for FreeBSD/OpenBSD/Solaris
- Add Windows ARM32 support (armasm preprocessing)
- Add platform detection: Android, FreeBSD, NetBSD, OpenBSD
- Add ARM32 variants: armv5l, armv6l, armv7l, armv7hf
- Fix macOS x64 FFI_MMAP_EXEC_WRIT definition in template

Documentation:
- Update README with accurate API documentation
- Clarify struct property access patterns
- Document packed struct support
- Add comprehensive limitations section

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@dmazzella dmazzella merged commit bfa8c39 into main Jan 23, 2026
8 checks passed
@dmazzella dmazzella deleted the relaxed-cohen branch January 24, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants