Repository navigation
test(data): exercise corrupted GeoPackage headers #1138
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -373,6 +373,35 @@ fn geopackage_in_memory() { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn geopackage_in_memory_handles_mutated_headers() { | ||||||
| let folder = tempfile::tempdir().unwrap(); | ||||||
| let path = folder.path().join("mutated.gpkg"); | ||||||
| write_gpkg(&path, false); | ||||||
| let original = std::fs::read(path).unwrap(); | ||||||
| let mut offsets: Vec<usize> = (0..100).collect(); | ||||||
| // SQLite pages have a short header; exercise the beginning of each one. | ||||||
| for page in (4096..original.len()).step_by(4096) { | ||||||
| offsets.extend(page..(page + 12).min(original.len())); | ||||||
| } | ||||||
| // Exercise flags and envelope metadata in actual GeoPackage geometry blobs. | ||||||
| let geometries: Vec<_> = | ||||||
| original.windows(4).enumerate().filter_map(|(i, bytes)| (bytes == b"GP\x00\x03").then_some(i)).take(3).collect(); | ||||||
|
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. Nits, grouped:
|
||||||
| assert_eq!(geometries.len(), 3); | ||||||
| for i in geometries { | ||||||
| offsets.extend(i..i + 8); | ||||||
|
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. Envelope is never mutated, despite the comment on line 387. The fixture writes each blob as an 8-byte header (
Suggested change
Also update the comment on line 387 to say it covers the header and the XY envelope. |
||||||
| } | ||||||
| offsets.sort_unstable(); | ||||||
| offsets.dedup(); | ||||||
| for offset in offsets { | ||||||
| let mut bytes = original.clone(); | ||||||
| bytes[offset] ^= 0xff; | ||||||
| if let Ok(source) = gpkg_mem::GpkgMemSource::open_shared(Shared(Arc::new(bytes)), None) { | ||||||
| let _ = source.read(&Request::all()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
| fn an_unknown_coordinate_system_is_reported() { | ||||||
| let p = dir().join("unknown_crs.gpkg"); | ||||||
|
|
||||||
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.
Page 1's B-tree header is skipped. The loop starts at 4096, so page 1 is never visited. Its B-tree header sits at byte 100, just past the 100-byte database header that line 383 covers, so bytes 100–111 are never mutated. The 4096 page size is also hard-coded; it is stored in the database header at bytes 16–17 (confidence: medium-high).