Skip to content

Commit 0bf2e55

Browse files
committed
fix: slice for zstd alignment
fixes: #5715 Signed-off-by: Alexander Droste <[email protected]>
1 parent 5339a58 commit 0bf2e55

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

encodings/zstd/src/array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ impl ZstdArray {
330330
.get(i + 1)
331331
.copied()
332332
.unwrap_or(value_bytes.len());
333+
334+
// Use slice_unaligned instead of slice to handle cases where frame boundaries
335+
// don't align with the buffer's alignment requirements (e.g., 64-byte aligned
336+
// buffers with 1-byte frame boundaries). ZSTD compression works on raw bytes
337+
// and doesn't require memory alignment.
333338
let uncompressed = &value_bytes.slice(frame_byte_starts[i]..frame_byte_end);
334339
let compressed = compressor
335340
.compress(uncompressed)

encodings/zstd/src/test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use vortex_array::arrays::VarBinViewArray;
99
use vortex_array::assert_arrays_eq;
1010
use vortex_array::validity::Validity;
1111
use vortex_array::vtable::ValidityHelper;
12+
use vortex_buffer::Alignment;
1213
use vortex_buffer::Buffer;
1314
use vortex_dtype::DType;
1415
use vortex_dtype::Nullability;
@@ -202,3 +203,16 @@ fn test_sliced_array_children() {
202203
let sliced = compressed.slice(0..4);
203204
sliced.children();
204205
}
206+
207+
#[test]
208+
fn test_zstd_alignment_issue() {
209+
// Scenario where a u8 array has a 64-byte alignment.
210+
// See: https://github.com/vortex-data/vortex/issues/5715
211+
let data = vec![0u8; 2];
212+
213+
let aligned_buffer = Buffer::copy_from_aligned(&data, Alignment::new(8));
214+
let array = PrimitiveArray::new(aligned_buffer, Validity::NonNullable);
215+
let compressed = ZstdArray::from_primitive(&array, 0, 1);
216+
217+
assert!(compressed.is_ok());
218+
}

0 commit comments

Comments
 (0)