This fixes the "panic: incorrect alignment" error that occurred in
postgres_types.zig:242 when processing binary array data from PostgreSQL.
The issue was caused by @alignCast failing when the network data wasn't
properly aligned for the struct type. The original code tried to directly
cast misaligned byte data to a struct pointer, which violates Zig's
alignment requirements.
## Root Cause
In PostgresBinarySingleDimensionArray.init(), the code used:
```zig
const this: *@This() = @alignCast(@ptrCast(@constCast(bytes.ptr)));
```
This would panic if bytes.ptr wasn't aligned to the struct's alignment
requirements (typically 4 bytes for i32 fields).
## Solution
- Read integer values safely using std.mem.readInt() with proper endianness
- Always allocate properly aligned memory using bun.default_allocator.alignedAlloc()
- Copy the original data to the aligned memory buffer
- Parse and set the struct fields explicitly instead of relying on memory layout
This ensures memory safety while maintaining compatibility with the existing
DataCell.deinit() infrastructure that expects bun.default_allocator allocations.
## Tests
- Added regression tests to verify the fix handles alignment correctly
- Added integration tests for array processing with various data sizes
- Verified that memory is properly allocated and can be freed correctly
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>