Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
aacde49
Harden parser bounds, numeric precision, and URL/range handling
giswqs Nov 25, 2026
09feddf
Address review feedback
giswqs Nov 25, 2026
d2622c0
Address Claude review feedback
giswqs Nov 25, 2026
e80b06b
Address CodeRabbit review feedback
giswqs Nov 25, 2026
1609251
Address Claude review feedback
giswqs Nov 25, 2026
2ad5cb1
Address Claude review feedback
giswqs Nov 25, 2026
fd493fd
Address Claude review feedback
giswqs Nov 25, 2026
87d0ebe
Address Claude review feedback
giswqs Nov 25, 2026
0e5b6ad
Merge origin/main into fix/parser-bounds-and-correctness
giswqs Nov 28, 2026
00c2a8e
Merge remote-tracking branch 'origin/main' into pr-2923
giswqs Nov 28, 2026
e88603c
Address review: exact whole-number text in min/max, drop unused to_wk…
giswqs Nov 28, 2026
14ea6f1
Merge remote-tracking branch 'origin/main' into pr-2923
giswqs Nov 28, 2026
6dd02d2
Walk LandXML surface children without a temporary Vec per element
giswqs Nov 29, 2026
a4b3e86
Merge remote-tracking branch 'origin/main' into pr-2923
giswqs Nov 29, 2026
0c55841
Size the OSM tag text budget from the file, not a fixed 256 MiB
giswqs Nov 29, 2026
ca9b4a3
Merge remote-tracking branch 'origin/main' into pr-2923
giswqs Nov 29, 2026
395c988
Cap the OSM text budget at the computer's planned share, by pointer w…
giswqs Nov 29, 2026
bfaef5c
Merge remote-tracking branch 'origin/main' into pr-2923
giswqs Nov 29, 2026
1781201
cargo fmt
giswqs Nov 29, 2026
b392abc
Say an inverted byte range as well as an overflowing one
giswqs Nov 29, 2026
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
5 changes: 5 additions & 0 deletions apps/rustgis-web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ async fn fetch_reached(
let max = limit.map(|n| n as u64).unwrap_or(64 << 20);
let (url, tail) = cache::split_tail(url);
let (url, range) = cache::split_range(url);
if let Some((a, b)) = range
&& cache::range_len(a, b).is_none()
{
return Err("byte range is inverted or its length overflows".into());
}
// Share native GET routing: explicit service logins outrank implicit S3 endpoint signing.
let bound = url;
let prepared = cache::prepare_get(url)?;
Expand Down
82 changes: 66 additions & 16 deletions crates/data/src/filegdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ fn read_table(name: &str, t: &[u8], x: &[u8], wkid: Option<u32>) -> Result<Optio
let mut no_footprint = 0usize;
// Shapes decoded, a multipatch's too (its M values go even when it has no footprint).
let mut decoded = 0usize;
let mut bad_geometries = 0usize;
let mut unread_dates = Vec::new();
let mut rounded_dates = Vec::new();
let mut budget = MAX_TABLE_FACES;
Expand Down Expand Up @@ -437,7 +438,10 @@ fn read_table(name: &str, t: &[u8], x: &[u8], wkid: Option<u32>) -> Result<Optio
geometry = patch.footprint;
}
Ok(Decoded::Empty) => {}
Err(()) => report.skipped += 1,
Err(()) => {
bad_geometries += 1;
report.skipped += 1;
}
}
}
// Kept as the file holds it, in its own system; counted when it has no place in
Expand Down Expand Up @@ -502,6 +506,14 @@ fn read_table(name: &str, t: &[u8], x: &[u8], wkid: Option<u32>) -> Result<Optio
format!("{unmerged} multipatches whose faces couldn't be merged are drawn as the outline of their points")
});
}
if bad_geometries > 0 {
let what = if bad_geometries == 1 {
"1 feature had an unreadable or non-finite geometry and is kept without geometry".to_string()
} else {
format!("{bad_geometries} features had unreadable or non-finite geometries and are kept without geometry")
};
report.messages.push(crate::loss::Note::loss(crate::loss::LossCode::DroppedGeometry, what));
}
Ok(Some((ds, report)))
}

Expand Down Expand Up @@ -988,6 +1000,12 @@ fn row_offsets(x: &[u8]) -> Result<Vec<(u64, usize)>> {
}
}
}
// Check for duplicate offsets in place without allocating an auxiliary hash set.
out.sort_unstable_by_key(|&(_, offset)| offset);
if out.windows(2).any(|w| matches!(w, [(_, a), (_, b)] if a == b)) {
return Err(bad("duplicate row offset"));
}
out.sort_unstable_by_key(|&(row, _)| row);
Ok(out)
}

Expand Down Expand Up @@ -1029,7 +1047,11 @@ fn decode_geometry(b: &[u8], def: &GeomDef, budget: &mut usize) -> std::result::
if vx == 0 || vy == 0 {
return Ok(Decoded::Empty);
}
Ok(Decoded::Geometry(Geometry::Point(Coord::new(x((vx - 1) as f64), y((vy - 1) as f64))), 0))
let (px, py) = (x((vx - 1) as f64), y((vy - 1) as f64));
if !px.is_finite() || !py.is_finite() {
Comment thread
giswqs marked this conversation as resolved.
Resolved
return Err(());
}
Ok(Decoded::Geometry(Geometry::Point(Coord::new(px, py)), 0))
}
// Multipoints.
8 | 18 | 20 | 28 | 53 => {
Expand Down Expand Up @@ -1136,7 +1158,11 @@ fn deltas(c: &mut Cur, n: usize, def: &GeomDef) -> std::result::Result<Vec<Coord
for _ in 0..n {
dx = dx.checked_add(c.varint().ok_or(())?).ok_or(())?;
dy = dy.checked_add(c.varint().ok_or(())?).ok_or(())?;
pts.push(Coord::new(dx as f64 / def.xy_scale + def.x0, dy as f64 / def.xy_scale + def.y0));
let (x, y) = (dx as f64 / def.xy_scale + def.x0, dy as f64 / def.xy_scale + def.y0);
if !x.is_finite() || !y.is_finite() {
return Err(());
}
pts.push(Coord::new(x, y));
}
Ok(pts)
}
Expand Down Expand Up @@ -1171,48 +1197,72 @@ pub(crate) fn signed_area(ring: &[Coord]) -> f64 {
}

/// A multipatch's faces, each its outer ring and then its holes: triangles from strips, fans and
/// triangle lists, and rings. At most [`MAX_FACES`]; the flag says some were left out.
/// triangle lists, and rings. At most [`MAX_FACES`] rings in total; the flag says some were left
/// out.
fn faces(parts: &[Vec<P3>], kinds: &[u64]) -> (Vec<Vec<Vec<P3>>>, bool) {
faces_limited(parts, kinds, MAX_FACES)
}

fn faces_limited(parts: &[Vec<P3>], kinds: &[u64], limit: usize) -> (Vec<Vec<Vec<P3>>>, bool) {
let mut faces: Vec<Vec<Vec<P3>>> = Vec::new();
let mut rings = 0usize;
let mut truncated = false;
for (part, &kind) in parts.iter().zip(kinds) {
// Faces past the cap are left out, within a part too (one strip can hold millions).
let room = MAX_FACES.saturating_sub(faces.len());
// Faces and inner rings past the cap are left out, within a part too (one strip can hold millions).
let room = limit.saturating_sub(rings);
let has = match kind {
0 | 1 => part.len().saturating_sub(2),
6 => part.len() / 3,
3 => 0,
_ => 1,
};
if has > room {
truncated = true;
}
if room == 0 {
break;
if truncated {
break;
}
continue;
}
match kind {
// Triangle strip, fan, triangles.
0 => faces.extend(part.windows(3).take(room).map(|w| vec![w.to_vec()])),
0 => {
let take = part.len().saturating_sub(2).min(room);
faces.extend(part.windows(3).take(take).map(|w| vec![w.to_vec()]));
rings += take;
}
1 => {
if let Some((first, rest)) = part.split_first() {
let take = rest.len().saturating_sub(1).min(room);
faces.extend(
rest.windows(2)
.filter_map(|w| match w {
[a, b] => Some(vec![vec![*first, *a, *b]]),
_ => None,
})
.take(room),
.take(take),
);
rings += take;
}
}
6 => faces.extend(part.as_chunks::<3>().0.iter().take(room).map(|w| vec![w.to_vec()])),
6 => {
let take = (part.len() / 3).min(room);
faces.extend(part.as_chunks::<3>().0.iter().take(take).map(|w| vec![w.to_vec()]));
rings += take;
}
// An inner ring is a hole in the face before.
3 => match faces.last_mut() {
Some(face) => face.push(part.clone()),
None => faces.push(vec![part.clone()]),
},
3 => {
match faces.last_mut() {
Some(face) => face.push(part.clone()),
None => faces.push(vec![part.clone()]),
}
rings += 1;
}
// Outer, first and plain rings.
_ => faces.push(vec![part.clone()]),
_ => {
faces.push(vec![part.clone()]);
rings += 1;
}
}
}
(faces, truncated)
Expand Down
70 changes: 70 additions & 0 deletions crates/data/src/filegdb/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,76 @@ fn filegdb_temporal_fields_keep_days_offsets_and_null_notices() {
}
}

#[test]
fn duplicate_row_offsets_are_refused() {
let (t, mut x) = table(0, &[F::Oid, F::Text("name")], &[vec![V::Text(Some("a"))], vec![V::Text(Some("b"))]]);
// Row index entries start at byte 16 with width 4; copy row 0's offset into row 1's slot.
let first_offset: [u8; 4] = x[16..20].try_into().unwrap();
x[20..24].copy_from_slice(&first_offset);
let err = row_offsets(&x).unwrap_err().to_string();
assert!(err.contains("duplicate row offset"), "{err}");
assert!(read_table("dup", &t, &x, None).is_err());
}

#[test]
fn non_finite_coordinates_are_rejected() {
let tiny_scale = GeomDef { wkt: String::new(), x0: 0.0, y0: 0.0, xy_scale: 1e-308, z0: 0.0, z_scale: 1.0 };
// Point (code 1): vx = 2, vy = 2 -> (1.0 / 1e-308) is finite; vx = 1000 -> 999 / 1e-308 = inf.
let mut pt = varuint(1);
pt.extend(varuint(1000));
pt.extend(varuint(2));
assert!(decode_geometry(&pt, &tiny_scale, &mut 100).is_err());

// Polyline (code 3): 2 points, 1 part, bbox(4 varuints), delta (1000, 0) overflows to inf.
let mut line = varuint(3);
line.extend(varuint(2));
line.extend(varuint(1));
for _ in 0..4 {
line.extend(varuint(0));
}
line.extend(varint(1000));
line.extend(varint(0));
line.extend(varint(0));
line.extend(varint(0));
assert!(decode_geometry(&line, &tiny_scale, &mut 100).is_err());

// End-to-end through `read_table`: lossy input emits a DroppedGeometry notice; clean input emits none.
let (mut t, x) = table(1, &[F::Oid, F::Shape { z: false, wkt: "" }], &[vec![V::Blob(pt.clone())]]);
let scale_bytes = 1000.0f64.to_le_bytes();
let pos = t.windows(8).position(|w| w == scale_bytes).expect("xy_scale in shape field header");
t[pos..pos + 8].copy_from_slice(&1e-308f64.to_le_bytes());
let (lossy_ds, lossy_report) = read_table("nonfinite", &t, &x, None).unwrap().unwrap();
assert_eq!(lossy_ds.features.len(), 1);
assert!(lossy_ds.features[0].geometry.is_none());
assert_eq!(lossy_report.skipped, 1);
assert!(
lossy_report.messages.iter().any(|m| {
m.loss == Some(crate::loss::LossCode::DroppedGeometry)
&& m.as_str() == "1 feature had an unreadable or non-finite geometry and is kept without geometry"
}),
"{lossy_report:?}"
);

let (clean_t, clean_x) = table(1, &[F::Oid, F::Shape { z: false, wkt: "" }], &[vec![V::Blob(pt)]]);
let (clean_ds, clean_report) = read_table("clean", &clean_t, &clean_x, None).unwrap().unwrap();
assert_eq!(clean_ds.features.len(), 1);
assert!(clean_ds.features[0].geometry.is_some());
assert_eq!(clean_report.skipped, 0);
assert!(!clean_report.messages.iter().any(|m| m.loss == Some(crate::loss::LossCode::DroppedGeometry)), "{clean_report:?}");
}

#[test]
fn multipatch_inner_rings_respect_ring_budget() {
let ring = vec![[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0]];
let parts = vec![ring; 6];
// 1 outer ring (kind 2) followed by 5 inner rings (kind 3).
let kinds = [2, 3, 3, 3, 3, 3];
let (got, truncated) = faces_limited(&parts, &kinds, 3);
assert!(truncated, "inner rings past the ring budget must set truncated");
let total_rings: usize = got.iter().map(Vec::len).sum();
assert_eq!(total_rings, 3);
}

/// A binary field and a geometry field after the first are left out of the layer, and said, once
/// for the table and by its name; a table without them says nothing (#2916).
#[test]
Expand Down
Loading
Loading