Repository navigation
fix(data): refuse a source over the read limit instead of reading a sample as the whole of it #1116
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19323,6 +19323,79 @@ impl Drop for GpkgRegressionFixture { | |
| } | ||
| } | ||
|
|
||
| /// Whole reads must refuse an oversized provider instead of returning its capped sample (#1108). | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| #[test] | ||
| fn oversized_geopackage_refuses_whole_reads_but_can_stream() { | ||
| use rustgis_data::{Dataset, Geometry, GeometryType, source::MAX_LIMIT}; | ||
|
|
||
| let fixture = GpkgRegressionFixture::new("whole-read-limit"); | ||
| let path = fixture.path(); | ||
| let count = MAX_LIMIT + 1; | ||
| let db = rusqlite::Connection::open(&path).unwrap(); | ||
| // A single SQLite statement generates the rows without keeping millions of features in Rust. | ||
| // The compact, valid point blob omits the optional envelope to keep this fixture small. | ||
| let mut blob = b"GP\x00\x01".to_vec(); | ||
| blob.extend_from_slice(&4326i32.to_le_bytes()); | ||
| blob.extend(rustgis_data::wkb::encode(&Geometry::Point(rustgis_geom::Coord::new(1.0, 20.0)))); | ||
| db.execute_batch( | ||
| "DELETE FROM roads; | ||
| UPDATE gpkg_contents SET min_x=1, max_x=1, min_y=20, max_y=20 WHERE table_name='roads';", | ||
| ) | ||
| .unwrap(); | ||
| assert_eq!( | ||
| db.execute( | ||
| "WITH RECURSIVE rows(fid) AS (SELECT 1 UNION ALL SELECT fid+1 FROM rows WHERE fid<?1) | ||
| INSERT INTO roads(fid, geom) SELECT fid, ?2 FROM rows", | ||
| rusqlite::params![count as i64, blob], | ||
| ) | ||
| .unwrap(), | ||
| count | ||
| ); | ||
| drop(db); | ||
| let assert_limit = |error: &str| { | ||
| assert!(error.contains(&count.to_string()), "missing source count: {error}"); | ||
| assert!(error.contains(&MAX_LIMIT.to_string()), "missing whole-read limit: {error}"); | ||
| }; | ||
|
|
||
| let mut s = Session::new(Project::default()); | ||
| let error = s.run("layer.addData", &json!({"path": path, "stream": false})).unwrap_err(); | ||
| assert_limit(&error); | ||
| assert!(s.map().layers.is_empty(), "a refused read must not add a partial layer"); | ||
|
|
||
| // A real file input to merge must fail even when the map already has a usable input layer. | ||
| let mut initial = Dataset::new("Initial", GeometryType::Point, vec![]); | ||
| initial.push_next(Some(Geometry::Point(rustgis_geom::Coord::new(0.0, 0.0))), vec![]); | ||
| let initial_id = s.map_mut().add_dataset(initial); | ||
| let error = s.run("gp.run", &json!({"tool": "merge", "params": {"inputs": [path], "output": "Merged"}})).unwrap_err(); | ||
| assert_limit(&error); | ||
| assert_eq!(s.map().layers.len(), 1); | ||
| assert!(s.map().layer_by_name("Merged").is_none()); | ||
| assert_eq!(s.map().layer(initial_id).unwrap().dataset.features.len(), 1); | ||
|
|
||
| let loaded = s.run("layer.addData", &json!({"path": path, "stream": true})).unwrap(); | ||
| assert_eq!(loaded["features"].as_u64(), Some(count as u64)); | ||
| let id = loaded["layer"].as_u64().unwrap() as u32; | ||
| assert!(s.map().layer(id).unwrap().is_streamed()); | ||
| let resident = s.map().layer(id).unwrap().dataset.features.len(); | ||
| assert!(resident < count); | ||
| let error = s.run("layer.loadAll", &json!({"layer": id})).unwrap_err(); | ||
| assert_limit(&error); | ||
| assert!(s.map().layer(id).unwrap().is_streamed()); | ||
| assert_eq!(s.map().layer(id).unwrap().dataset.features.len(), resident); | ||
|
|
||
| let output = fixture.dir.join("refused.geojson"); | ||
| let error = s.run("share.exportLayer", &json!({"layer": id, "path": output})).unwrap_err(); | ||
| assert_limit(&error); | ||
| assert!(!output.exists(), "a refused export must not write a partial file"); | ||
| assert!(s.map().layer(id).unwrap().is_streamed()); | ||
| assert_eq!(s.map().layer(id).unwrap().dataset.features.len(), resident); | ||
| assert_eq!(s.map().layers.len(), 2); | ||
|
|
||
| assert_limit(&rustgis_data::io::read_path(&path).unwrap_err().to_string()); | ||
| assert_limit(&rustgis_data::io::read_owned("oversized.gpkg", std::fs::read(&path).unwrap()).unwrap_err().to_string()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quality / test cost (confidence: medium). This fixture holds 2,000,001 rows plus an R-tree entry for each, so the
Consider checking the refusal on a path-based call only, or asserting the file size first so a failure names the cause. The fixture's cost in CI time is also worth a note in the PR description.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Measured: the fixture is ~83 MB (2,000,001 rows of fid + a 29-byte point blob; |
||
| } | ||
|
|
||
| #[cfg(not(target_arch = "wasm32"))] | ||
| fn assert_gpkg_regression_clean(s: &mut Session) { | ||
| let pending = s.run("gpkg.pendingEdits", &json!({"layer": "R"})).unwrap(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low-confidence fragility, not a bug on today's paths.
Batch::default()hascomplete: false, and several providers return that default unchanged on early exits:mysql.rs(limit == 0, and a lon/lat table with an extent off the world),postgis.rs:1353andsqlserver.rs:735/741. Before this change, an incomplete empty batch was only a sample notice. Now anycomplete: falseon a whole read becomes an error.materializecallsread(Request::all())with no extent and a non-zero limit, so these returns aren't reached from here. A future caller that passes an extent, or alimitof 0, to a source would get a "could not read the whole source (0 of 0 features…)" error for an empty result. Settingcomplete: trueon those early returns (they hold no matches, so nothing was left out) would keep the new check honest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
materializealways readsRequest::all()(no extent, non-zero limit), so those early returns aren't reachable from a whole read. Changing provider early exits is out of scope here; follow-up candidate. (reviewed at 05ff232)