Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on data slice accesses #358

Merged
merged 3 commits into from
Oct 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/accessor/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ fn buffer_view_slice<'a, 's>(
) -> Option<&'s [u8]> {
let start = view.offset();
let end = start + view.length();
get_buffer_data(view.buffer()).map(|slice| &slice[start..end])
get_buffer_data(view.buffer())
.map(|slice| slice.get(start..end))
.flatten()
repi marked this conversation as resolved.
Show resolved Hide resolved
}

/// General iterator for an accessor.
Expand Down Expand Up @@ -297,7 +299,7 @@ impl<'a, 's, T: Item> Iter<'s, T> {
let start = accessor.offset();
let end = start + stride * (accessor.count() - 1) + mem::size_of::<T>();
let subslice = if let Some(slice) = buffer_view_slice(view, &get_buffer_data) {
&slice[start..end]
slice.get(start..end)?
} else {
return None;
};
repi marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -314,7 +316,7 @@ impl<'a, 's, T: Item> Iter<'s, T> {
let subslice = if let Some(slice) = buffer_view_slice(view, &get_buffer_data) {
let start = indices.offset() as usize;
let end = start + stride * (sparse_count - 1) + index_size;
&slice[start..end]
slice.get(start..end)?
} else {
return None;
};
Expand All @@ -336,7 +338,7 @@ impl<'a, 's, T: Item> Iter<'s, T> {
let subslice = if let Some(slice) = buffer_view_slice(view, &get_buffer_data) {
let start = values.offset() as usize;
let end = start + stride * (sparse_count - 1) + mem::size_of::<T>();
&slice[start..end]
slice.get(start..end)?
} else {
return None;
};
Expand All @@ -359,7 +361,7 @@ impl<'a, 's, T: Item> Iter<'s, T> {
let start = accessor.offset();
let end = start + stride * (accessor.count() - 1) + mem::size_of::<T>();
let subslice = if let Some(slice) = buffer_view_slice(view, &get_buffer_data) {
&slice[start..end]
slice.get(start..end)?
} else {
return None;
};
Expand Down