Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
57ae18c
fix(data): the PDF reader says what it couldn't draw or read, and rea…
flight1973 Nov 18, 2026
eb509cb
fix(data): the PDF reader names fonts not in the file and says what i…
flight1973 Nov 19, 2026
d31ecef
fix(data): the PDF reader names only the fonts it draws in a stand-in…
flight1973 Nov 19, 2026
95c5c1c
fix(data): the PDF font search stops at a byte and work budget, and k…
flight1973 Nov 19, 2026
6a44ba3
Merge remote-tracking branch 'origin/main' into prep/pdf-reader
flight1973 Nov 20, 2026
13aafb8
fix(data): read bytes below 0x80 of an unmarked UTF-8 PDF text string…
flight1973 Nov 20, 2026
5b4298f
fix(data): a File Geodatabase says unreadable WKT characters only whe…
flight1973 Nov 20, 2026
ed347fe
fix(data): the PDF font search follows what hayro draws, stops with i…
flight1973 Nov 20, 2026
e333775
fix(data): the PDF font search reads graphics state fonts, inherited …
flight1973 Nov 20, 2026
f76c323
fix(data): a File Geodatabase counts unreadable name characters only …
flight1973 Nov 20, 2026
eb3f867
fix(data): the PDF font search names stand-ins for unreadable program…
flight1973 Nov 20, 2026
235fe50
fix(data): the PDF font search loads each font program once, within i…
flight1973 Nov 20, 2026
7778491
fix(data): a File Geodatabase says how many characters of its text va…
flight1973 Nov 21, 2026
f29d993
fix(data): the PDF font search skips what hayro won't draw, keeps nam…
flight1973 Nov 21, 2026
c940ec7
Merge remote-tracking branch 'origin/main' into finish/pdf-reader
flight1973 Nov 30, 2026
7b96882
fix(data): PDF layer labels, table names and the encoding notices say…
flight1973 Nov 30, 2026
5727694
Merge remote-tracking branch 'origin/main' into finish/pdf-reader
flight1973 Nov 30, 2026
1f2c9a0
fix(data): say a FileGDB or feature service WKT that can't be read be…
flight1973 Dec 3, 2026
0ce6732
fix(data): open a PDF layer by its 0.9 name, and bound and sharpen th…
flight1973 Dec 3, 2026
f43b528
fix(data): the PDF font search charges a shared font program's decode…
flight1973 Dec 3, 2026
0a9ffc8
Merge origin/main into fix/pdf-reader-says-what-it-drops
flight1973 Dec 4, 2026
6635522
fix(data): count a PDF layer's parent names it couldn't read past the…
flight1973 Dec 4, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ unicode-segmentation = "1.13"
tiff = "0.11"
# Reading PDF pages (GeoPDFs, and plain PDFs as scans) on the desktop (#2336).
hayro = "0.9"
# The version hayro reads fonts with: to tell a font program in the file it can't load.
hayro-font = "0.5"
# LZW chunks the tiff crate fails on (issue #350), decoded with the version it uses.
weezl = "0.2"
# The tests' Zstandard-compressed GeoTIFFs (the version the tiff crate decodes with).
Expand Down
3 changes: 2 additions & 1 deletion crates/data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ workspace = true

[dependencies]
hayro = { workspace = true, optional = true }
hayro-font = { workspace = true, optional = true }
rustgis-geom = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down Expand Up @@ -91,7 +92,7 @@ rustix = { version = "1.1", features = ["process", "fs"] }
# PDF pages read as rasters, GeoPDFs placed by their coordinates (#2336): the desktop, command line
# and Python apps turn it on; the browser and phone apps leave it off, where it would add megabytes
# for a format seldom opened there. An app built on the engine may turn it on anywhere.
pdf = ["dep:hayro"]
pdf = ["dep:hayro", "dep:hayro-font"]
# The JSON Schema of the saved types (`cargo xtask schema`).
schema = ["dep:schemars", "rustgis-geom/schema"]
# Marks direct uses of the row vector and of `Feature`'s fields as deprecated, so that
Expand Down
20 changes: 9 additions & 11 deletions crates/data/src/esripbf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
//! text values (field names and the WKT included) that would take more than 512 MB. Answers are
//! hostile input: every length is checked, and nothing is read past the end.

use crate::filegdb::{crs_of_code, esri_wkt_over_code};
use crate::{DataError, Dataset, Field, FieldType, Geometry, GeometryType, ReadReport, Result, Value};
use rustgis_geom::Coord;

Expand Down Expand Up @@ -373,21 +372,20 @@ pub fn read_page_within(bytes: &[u8], name: &str, limit: usize) -> Result<Page>
Some(bytes) => spatial_reference(bytes, &mut tally)?,
None => (None, None, true),
};
// Only when the WKT may name the system: a code RustGIS knows goes first, unless the WKT is
// read in its place. If the replaced bytes break the WKT, it can't be told whether the WKT
// would have won, so that's said too. The WKT is looked at only when it isn't UTF-8, as this
// runs for every page.
// Whenever there is WKT: where a code RustGIS knows places the layer, the WKT is still read
// for the shifts and grids it gives that the code doesn't apply, which the replaced bytes
// could hide, and that is said with it. If the replaced bytes break the WKT, it can't be told
// whether the WKT would have won. The WKT is looked at only when it isn't UTF-8, as this runs
// for every page.
// What reading the system says (its WKT's text, and what it assumes) holds only for a
// geometry read in it.
let said_before = report.messages.len();
if !wkt_utf8
&& (code.and_then(crs_of_code).is_none()
|| esri_wkt_over_code(code, wkt.as_deref()).is_some()
|| !wkt.as_deref().is_some_and(crate::raster::wkt::parses))
{
if !wkt_utf8 && wkt.is_some() {
// Decided as `esri_crs` places it, so the two readers agree.
let placed = crate::filegdb::placed_beside(code, wkt.as_deref());
report.messages.push(crate::loss::Note::loss(
crate::loss::LossCode::ChangedEncoding,
"the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD",
format!("the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD{placed}"),
));
}
let (crs, to_lonlat) = crate::filegdb::esri_crs(code, wkt.as_deref(), &mut report)?;
Expand Down
58 changes: 37 additions & 21 deletions crates/data/src/esripbf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,24 @@ fn a_wkt_that_isnt_utf8_is_said() {
let rows = answer(&[message(8, &message(5, wkt)), transform(false, 1.0, 0.0, 0.0), feature(&[])]);
let (_, report) = read(&rows, "t").unwrap();
assert_eq!(report.messages.first().map(|m| m.loss), Some(None), "{:?}", report.messages);
// Unused when a code RustGIS knows names the system: nothing to say.
let with_code = answer(&[
message(8, &[number(1, 4326), message(5, wkt)].concat()),
transform(false, 1.0, 0.0, 0.0),
feature(&[geometry(&[], &[1, 2])]),
]);
let (_, report) = read(&with_code, "t").unwrap();
// A code RustGIS knows names the system: the WKT is still read for what the code doesn't
// apply, so it's said with the code that placed it.
let with_code = |wkt: &[u8]| {
answer(&[
message(8, &[number(1, 4326), message(5, wkt)].concat()),
transform(false, 1.0, 0.0, 0.0),
feature(&[geometry(&[], &[1, 2])]),
])
};
let (_, report) = read(&with_code(wkt), "t").unwrap();
assert_eq!(
report.messages.texts().collect::<Vec<_>>(),
["the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD; \
the layer is placed by its code, and the WKT read only for what the code doesn't apply"]
);
// The same WKT in UTF-8: nothing to say.
let clean = String::from_utf8_lossy(wkt).replace('\u{FFFD}', "");
let (_, report) = read(&with_code(clean.as_bytes()), "t").unwrap();
assert!(report.messages.is_empty(), "{:?}", report.messages);
}

Expand Down Expand Up @@ -523,36 +534,41 @@ fn a_wkts_own_shift_wins_over_its_wkid() {
let not_utf8 = [b"PROJCS[\"\xff", other.strip_prefix("PROJCS[\"").unwrap().as_bytes()].concat();
let (_, messages) = at(&page([number(1, 27700), message(5, &not_utf8)].concat()));
assert!(messages.iter().any(|m| m.contains("isn't valid UTF-8")), "{messages:?}");
// The same byte in the code's own WKT gives no other shift: the code is read, nothing to say.
// The same byte in the code's own WKT gives no other shift: the code is read, and what the WKT
// lost is said with that, as the WKT is still read for what the code doesn't apply.
let by_code_note = "the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD; \
the layer is placed by its code, and the WKT read only for what the code doesn't apply";
let not_utf8 = [b"PROJCS[\"\xff", bng.strip_prefix("PROJCS[\"").unwrap().as_bytes()].concat();
let (p, messages) = at(&page([number(1, 27700), message(5, &not_utf8)].concat()));
assert!((p.x - by_code.x).abs() < 1e-9 && (p.y - by_code.y).abs() < 1e-9, "{p:?} {by_code:?}");
assert_eq!(messages.texts().collect::<Vec<_>>(), [by_code_note]);
assert_eq!(messages.clone().into_vec()[0].loss, Some(crate::loss::LossCode::ChangedEncoding));
// Clean WKT with the code: nothing said.
let (_, messages) = at(&page([number(1, 27700), message(5, bng.as_bytes())].concat()));
assert!(messages.is_empty(), "{messages:?}");
// A byte that breaks the WKT: the code is read, and it's said, as the WKT might have won.
// A byte that breaks the WKT: the code is read, and it's said that the WKT, unread, might have
// placed it otherwise.
let broken_note = "the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD; \
with them the WKT can't be read, so the layer is placed by its code, and the WKT might have placed it otherwise";
let broken = [b"PROJCS\xff\"", other.strip_prefix("PROJCS[\"").unwrap().as_bytes()].concat();
assert!(!crate::raster::wkt::parses(&String::from_utf8_lossy(&broken)));
let (p, messages) = at(&page([number(1, 27700), message(5, &broken)].concat()));
assert!((p.x - by_code.x).abs() < 1e-9 && (p.y - by_code.y).abs() < 1e-9, "{p:?} {by_code:?}");
assert_eq!(
messages.texts().collect::<Vec<_>>(),
["the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD"]
);
// A non-EPSG Esri code: its WKT is read only for another body's system, so a byte that
// breaks the WKT is said, and a byte in a name is not. The WKT's shift (OSGB 1936's) is set
// aside for the code's, which is said.
assert_eq!(messages.texts().collect::<Vec<_>>(), [broken_note]);
// A non-EPSG Esri code: its WKT is read for another body's system and for the shift it sets
// aside, so a byte that breaks the WKT is said, and a byte in a name is said with the code that
// placed it. The WKT's shift (OSGB 1936's) is set aside for the code's, which is said.
assert!(Crs::from_epsg(102033).is_none() && crate::filegdb::crs_of_code(102033).is_some());
let albers = crate::filegdb::crs_of_code(102033).unwrap().transformer().unwrap().to_lonlat(xy).unwrap();
let (p, messages) = at(&page([number(1, 102033), message(5, &broken)].concat()));
assert!((p.x - albers.x).abs() < 1e-9 && (p.y - albers.y).abs() < 1e-9, "{p:?} {albers:?}");
assert_eq!(
messages.texts().collect::<Vec<_>>(),
["the coordinate system's WKT isn't valid UTF-8; the bytes that can't be read are replaced with U+FFFD"]
);
assert_eq!(messages.texts().collect::<Vec<_>>(), [broken_note]);
let (p, messages) = at(&page([number(1, 102033), message(5, &not_utf8)].concat()));
assert!((p.x - albers.x).abs() < 1e-9 && (p.y - albers.y).abs() < 1e-9, "{p:?} {albers:?}");
assert_eq!(
messages,
messages.texts().collect::<Vec<_>>(),
[
by_code_note,
"coordinate system: the file's own shift to WGS 84 is set aside for ESRI:102033's, because ArcGIS keeps transformations apart from the system"
]
);
Expand Down
Loading
Loading