fix(arrow): reject fractional array pitches and avoid rectangle overflow

This commit is contained in:
Jan Petykiewicz 2026-11-15 19:50:49 -08:00
commit f38d88e3cf

View file

@ -822,9 +822,9 @@ fn boundary_to_rect(vertices: &[i32]) -> Option<[i32; 4]> {
let mut seen_corners: u8 = 0;
for ii in 0..4 {
let jj = (ii + 1) % 4;
let dx = xs[jj] - xs[ii];
let dy = ys[jj] - ys[ii];
if (dx == 0) == (dy == 0) {
let same_x = xs[jj] == xs[ii];
let same_y = ys[jj] == ys[ii];
if same_x == same_y {
return None;
}
@ -922,7 +922,14 @@ fn read_ref<'a>(
}
let pitch = |end: i32, origin: i32, count: i16| {
let value = (i64::from(end) - i64::from(origin)) / i64::from(count);
let delta = i64::from(end) - i64::from(origin);
let divisor = i64::from(count);
if delta % divisor != 0 {
return Err((input, crate::basic::ErrType::Failed(
"AREF pitch is not an integer database-unit increment; the Arrow schema cannot represent it exactly".to_string()
)));
}
let value = delta / divisor;
i32::try_from(value).map_err(|_| (input, crate::basic::ErrType::Failed(
"AREF pitch exceeds signed 32-bit coordinate range".to_string()
)))