Repository navigation
fix: a truncated element no longer spins the reader forever - #78
Closed
PlenoraETL wants to merge 1 commit into
Closed
PlenoraETL wants to merge 1 commit into
PlenoraETL wants to merge 1 commit into
Conversation
Six elements hang on `main` when their end tag never arrives: `Point`, `LineString`, `LinearRing`, `Placemark`, `Data` and `SchemaData`. Each waits for a specific `Event::End` and ignores everything else, so once the document runs out `next_event` hands back `Event::Eof` forever and the loop keeps asking. A 314-byte input found by a fuzzer ran for over a hundred seconds before I stopped it. Only these six were measured to hang. Other loops in the file have the same shape and no `Eof` arm either, and they return: the missing arm is not by itself the defect, so they are left alone. `read_geom_props` covers three of the six, which is why four loops are touched and not six. The fix rejects with `Error::InvalidInput`, which already exists - no new variant, no change to the enum. Recovering what was read so far would be a different contract, and that is the maintainer's choice rather than mine; I have gone for the smaller change. A note on one road not taken, since it looks tempting: a flag in `next_event` that errors on the second `Eof` is a single-place fix and **wrong**. `read_elements` is re-entrant, and a legitimate document consumes more than one `Eof` - four tests in this suite go red. Three tests. The first asserts the six elements are rejected: if the defect came back it would not fail, it would hang, and CI would time out instead - which is a property of the defect and the reason the list is asserted rather than described. The second covers the shape the fuzzer produced. The third is the counter-proof that well formed documents still parse, without which a change that rejected everything would pass the other two. Found by the fuzzing CI of https://github.com/PlenoraETL/plenora-IO-tools
PlenoraETL
added a commit
to PlenoraETL/plenora-IO-tools
that referenced
this pull request
Sep 10, 2026
Il conteggio diceva «27 allineate su 28» e l'elenco della migrazione ne descriveva sei. Nessuno dei due era falso da solo, e insieme nascondevano `shapefile`, indietro di tre minor. La causa e' strutturale, non una svista: i tre fork governati sono **sia** dipendenze dirette del workspace **sia** voci della sezione `fork`, e chi compilava l'elenco ne aveva portata una sola. Un elenco tenuto a mano accanto a un manifesto diverge; la sola difesa e' che qualcosa li confronti. `check_dependency_pins.py` lo fa ora, e pretende tre cose senza bisogno di rete: ogni crate nominato in `fork` compare fra le voci della migrazione; ogni voce e' una dipendenza diretta vera, perche' l'elenco puo' divergere anche nell'altro senso; e `allineate + indietro` uguaglia il numero di dipendenze dirette, cosi' un conteggio non puo' descrivere un insieme diverso da quello che c'e'. Non pretende invece che **ogni** dipendenza compaia fra le voci: quell'elenco nomina cio' che ha richiesto lavoro, ed elencarne ventotto lo renderebbe illeggibile senza dire niente di piu'. Alla prima corsa ha trovato una seconda lacuna: `dxf`, fork e dipendenza diretta, fuori dall'elenco per la stessa ragione. Non era indietro -- e' alla sua ultima release -- quindi non nascondeva niente **oggi**, ma il giorno in cui pubblichera' una release nuova sarebbe rimasto fuori come lo era `shapefile`. Una lacuna che non fa danno oggi non e' una lacuna diversa: e' la stessa, in attesa. Cinque sonde: le tre direzioni del controllo, il registro reale, e la controprova che un registro coerente passa -- senza la quale le altre passerebbero anche se il controllo rifiutasse qualunque cosa. Registrata anche `georust/kml#78`, inviata il 2026-09-10: sei contributi inviati, due uniti, quattro aperte. L1 85/85. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012PRhkFKzTjuqBjaUXCou96
pjsier
requested changes
Oct 2, 2026
pjsier
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR! And sorry for the delay. I have some small feedback items but otherwise this looks good
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| /// A truncated element must not keep the reader spinning. |
Member
There was a problem hiding this comment.
Small item, but can we move these to the bottom so that they're not above use super::*?
Comment on lines
+1310
to
+1311
| /// not go red if the defect came back - it would hang, and CI would time | ||
| /// out instead. That is a property of the defect, and the reason the list |
Member
There was a problem hiding this comment.
To be safe here, can we add a timeout instead so that the failure behavior is a failure and not hanging?
We could add something like this to the tests module and wrap it
fn rejected_within_timeout(doc: &str) -> Option<bool> {
let doc = doc.to_owned();
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
// Send only a bool, so Kml/Error don't need to be Send.
let _ = tx.send(doc.parse::<Kml>().is_err());
});
rx.recv_timeout(Duration::from_secs(5)).ok()
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Six elements hang on
mainwhen their end tag never arrives:Point,LineString,LinearRing,Placemark,DataandSchemaData. Each waits for a specificEvent::Endand ignores everything else, so once the document runs outnext_eventhands backEvent::Eofforever and the loop keeps asking. A 314-byte input found by a fuzzer ran for over a hundred seconds before I stopped it.Only these six were measured to hang. Other loops in the file have the same shape and no
Eofarm either, and they return — I checked all thirty-one elements with a three-second budget each, against both the published crate andmain. The missing arm is not by itself the defect, so the others are left alone.read_geom_propscovers three of the six, which is why four loops are touched and not six.The fix rejects with
Error::InvalidInput, which already exists — no new variant, no change to the enum. Recovering what was read so far would be a different contract, and that is your choice rather than mine; I have gone for the smaller change and would be glad to switch if you prefer recovery.One road not taken, since it looks tempting: a flag in
next_eventthat errors on the secondEofis a single-place fix and wrong.read_elementsis re-entrant, and a legitimate document consumes more than oneEof— four tests in this suite go red.Tests
Three. The first asserts the six elements are rejected: if the defect came back it would not fail, it would hang, and CI would time out instead — which is a property of the defect and the reason the list is asserted rather than described in a comment. The second covers the shape the fuzzer produced. The third is the counter-proof that well formed documents still parse, without which a change that rejected everything would pass the other two.
Verified on
main: 48 + 4 + 12 tests green,cargo clippy --all-targets -- -D warningsclean,cargo fmt --checkclean.Found by the fuzzing CI of https://github.com/PlenoraETL/plenora-IO-tools