From aa1ff41d0c6ac868c7e872c25d4a5ac5cf8e6d7e Mon Sep 17 00:00:00 2001 From: Alexander Droste Date: Thu, 27 Aug 2026 12:12:40 +0100 Subject: [PATCH 1/3] fix: validate buffer slice alignment Prevent slices from reporting an alignment stronger than their source buffer and cover preferred-versus-required alignment propagation. Signed-off-by: Alexander Droste --- vortex-buffer/src/buffer.rs | 19 +++++++++++++++++-- vortex-buffer/src/buffer_mut.rs | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/vortex-buffer/src/buffer.rs b/vortex-buffer/src/buffer.rs index a59fff825f8..2c1bb6f0684 100644 --- a/vortex-buffer/src/buffer.rs +++ b/vortex-buffer/src/buffer.rs @@ -335,8 +335,8 @@ impl Buffer { /// /// # Panics /// - /// Requires that `begin <= end` and `end <= self.len()`. - /// Also requires that both `begin` and `end` are aligned to the given alignment. + /// Requires that `begin <= end` and `end <= self.len()`. The buffer and the byte offset at + /// `begin` must be aligned to `alignment`. pub fn slice_with_alignment( &self, range: impl RangeBounds, @@ -374,6 +374,12 @@ impl Buffer { let begin_byte = begin * size_of::(); let end_byte = end * size_of::(); + if !self.alignment.is_aligned_to(alignment) { + vortex_panic!( + "Slice alignment {alignment} must not be stronger than buffer alignment {}", + self.alignment + ); + } if !alignment.is_offset_aligned(begin_byte) { vortex_panic!( "range start must be aligned to {alignment:?}, byte {}", @@ -815,6 +821,15 @@ mod test { buf.slice(1..2); } + #[test] + #[should_panic(expected = "must not be stronger than buffer alignment")] + fn test_slice_with_alignment_cannot_strengthen_alignment() { + let buf = ByteBuffer::from(vec![0u8, 1]); + assert_eq!(buf.alignment(), Alignment::of::()); + + buf.slice_with_alignment(0..1, Alignment::new(256)); + } + #[test] fn bytes_buf() { let mut buf = ByteBuffer::copy_from("helloworld".as_bytes()); diff --git a/vortex-buffer/src/buffer_mut.rs b/vortex-buffer/src/buffer_mut.rs index e5cb03c558b..2f006e3e75e 100644 --- a/vortex-buffer/src/buffer_mut.rs +++ b/vortex-buffer/src/buffer_mut.rs @@ -1011,6 +1011,19 @@ mod test { assert_eq!(buf.as_slice(), b"helloworld"); } + #[test] + fn test_preferred_alignment_is_not_reported() { + let alignment = Alignment::of::(); + let buf = BufferMut::::with_capacity_preferred_aligned( + 1, + alignment, + Some(Alignment::DEFAULT_ALIGNMENT), + ); + + assert_eq!(buf.alignment(), alignment); + assert_eq!(buf.freeze().alignment(), alignment); + } + #[test] fn buffer_mut_zeroed() { const LEN: usize = 17; From c54c1f8f948441e84adb829cdbb0511bd5841507 Mon Sep 17 00:00:00 2001 From: Alexander Droste Date: Thu, 27 Aug 2026 13:53:26 +0100 Subject: [PATCH 2/3] Update vortex-buffer/src/buffer.rs Co-authored-by: Joe Isaacs Signed-off-by: Alexander Droste --- vortex-buffer/src/buffer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vortex-buffer/src/buffer.rs b/vortex-buffer/src/buffer.rs index 2c1bb6f0684..89d3a00130d 100644 --- a/vortex-buffer/src/buffer.rs +++ b/vortex-buffer/src/buffer.rs @@ -376,7 +376,7 @@ impl Buffer { if !self.alignment.is_aligned_to(alignment) { vortex_panic!( - "Slice alignment {alignment} must not be stronger than buffer alignment {}", + "Slice alignment {alignment} must not be wider than buffer alignment {}", self.alignment ); } From 66a433a59329df3953bbf9990e97c8defdf7e502 Mon Sep 17 00:00:00 2001 From: Alexander Droste Date: Thu, 27 Aug 2026 14:21:48 +0100 Subject: [PATCH 3/3] Update vortex-buffer/src/buffer.rs Co-authored-by: Joe Isaacs Signed-off-by: Alexander Droste --- vortex-buffer/src/buffer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vortex-buffer/src/buffer.rs b/vortex-buffer/src/buffer.rs index 89d3a00130d..ae7224d7860 100644 --- a/vortex-buffer/src/buffer.rs +++ b/vortex-buffer/src/buffer.rs @@ -376,7 +376,7 @@ impl Buffer { if !self.alignment.is_aligned_to(alignment) { vortex_panic!( - "Slice alignment {alignment} must not be wider than buffer alignment {}", + "Slice alignment {alignment} must be wider than buffer alignment {}", self.alignment ); }