From 1886e30101cb96921b2679c76e896e1464a3b07e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 7 Nov 2026 18:44:53 -0800 Subject: [PATCH] linesweeper: add_bez_path leaves the arena unchanged when a subpath is open Segments::add_bez_path pushed every segment of a subpath before checking that it was closed, and returned NonClosedPath without removing them. For M0,0 L10,0 L5,10 Z M20,0 L30,5 L25,10 the arena kept five segments with no entrances, the last linked to index 5 of a 5-segment arena, so check_invariants panicked with an index out of bounds. Adding a closed square afterwards linked the open piece into the square, and the sweep visited only the square's 4 of 9 segments. add_bez_path now truncates the arena back to its length before the call when it returns the error. README.craft.md, SOURCE.json and NOTICE record the local patch. --- NOTICE | 6 +++--- vendor/linesweeper/README.craft.md | 22 +++++++++++++++------- vendor/linesweeper/SOURCE.json | 8 +++++--- vendor/linesweeper/src/lib.rs | 18 ++++++++++++++++++ vendor/linesweeper/src/segments.rs | 23 ++++++++++++++++++++++- 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/NOTICE b/NOTICE index bd88d43e7a..70c163182c 100644 --- a/NOTICE +++ b/NOTICE @@ -218,10 +218,10 @@ applications retain their own document-font selection and licensing policy. linesweeper linesweeper 0.5.0 (https://crates.io/crates/linesweeper/0.5.0), MIT OR Apache-2.0, is stored in -vendor/linesweeper with its upstream license files and no file changed. Its manifest names Joe Neeman +vendor/linesweeper with its upstream license files and one local patch. Its manifest names Joe Neeman as author, and its LICENSE-MIT reads "Copyright (c) 2018 Raph Levien". See -vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance and the files -left out. +vendor/linesweeper/README.craft.md and vendor/linesweeper/SOURCE.json for provenance, the local +change and the files left out. Platform lifecycle source provenance diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index f683ca53de..f3fc7663cd 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,23 @@ # Local linesweeper 0.5.0 copy -This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and no -file changed. `.cargo_vcs_info.json` names the commit it was packaged from, +This is the crates.io linesweeper 0.5.0 package (MIT OR Apache-2.0) with some files left out and the +changes listed under Local changes. `.cargo_vcs_info.json` names the commit it was packaged from, `824b0791a750f7b27b8edcbb6c6244d0e629875e`. That commit is not in the GitHub repository the manifest names, which is archived; its README says development moved off GitHub. -Every file here except this one and `SOURCE.json` is byte for byte the file in the `.crate` archive. -`SOURCE.json` records the hash of the `.crate` download (`source_archive_sha256`) and, for every file -kept, the hash in the package (`source_sha256`) and the hash here (`sha256`). `upstream_repository` is -null because no public repository this copy can name holds `upstream_revision`. `local_patches` is -empty. +Every file here except this one, `SOURCE.json` and the files under Local changes is byte for byte the +file in the `.crate` archive. `SOURCE.json` records the hash of the `.crate` download +(`source_archive_sha256`) and, for every file kept, the hash in the package (`source_sha256`) and the +hash here (`sha256`). `upstream_repository` is null because no public repository this copy can name +holds `upstream_revision`. `local_patches` describes each local change. + +## Local changes + +| Change | Code comment label | Touches | Tests | +|---|---|---|---| +| `Segments::add_bez_path` leaves the arena unchanged when a subpath is not closed, instead of keeping the segments it pushed before the open subpath, the last of them linked to an index past the end of the arena | `Craft patch (add_bez_path error)` | `src/segments.rs`, `src/lib.rs` | `tests::add_bez_path_error_leaves_segments_unchanged` | + +Every change here updates this table and `SOURCE.json` in the same commit. `omitted_files` lists the 43 files of the package left out here, with their hashes: diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index 9c71e51add..ec10a83262 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -7,7 +7,9 @@ "upstream_repository": null, "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", - "local_patches": [], + "local_patches": [ + "In `src/segments.rs`, `Segments::add_bez_path` removes the segments it pushed when a subpath is not closed. Without it, adding `M0,0 L10,0 L5,10 Z M20,0 L30,5 L25,10` returns `NonClosedPath` but keeps five segments with no entrances, the last linked to index 5 of a 5-segment arena: `check_invariants` panics with an index out of bounds, and after a closed square is added the open piece is linked into the square and the sweep visits only the square's 4 of 9 segments. With it, the arena is unchanged after the error and the square's 4 segments are all entered. The test `tests::add_bez_path_error_leaves_segments_unchanged` in `src/lib.rs` covers it." + ], "files": [ { "path": ".cargo_vcs_info.json", "source_sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc", "source_git_blob": null, "sha256": "47fba6a9dbdf445a5c97f783c9be62093035f9d5e5cdc2cf3216ad8259bcd8fc" }, { "path": ".gitignore", "source_sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0", "source_git_blob": null, "sha256": "88b59092499ae05234330eb7d0b01e953e969caf05261530e3765eef02536cf0" }, @@ -37,12 +39,12 @@ { "path": "src/curve/transverse.rs", "source_sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e", "source_git_blob": null, "sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e" }, { "path": "src/generators.rs", "source_sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef", "source_git_blob": null, "sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef" }, { "path": "src/geom.rs", "source_sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08", "source_git_blob": null, "sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08" }, - { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6" }, + { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "e71cce5fb386773e9e08372a76001511de4080b999e78525a0f768cd6e543fa1" }, { "path": "src/num.rs", "source_sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a", "source_git_blob": null, "sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a" }, { "path": "src/order.rs", "source_sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596", "source_git_blob": null, "sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596" }, { "path": "src/perturbation.rs", "source_sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5", "source_git_blob": null, "sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5" }, { "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0" }, - { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc" }, + { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "5b3ca2c01ac51b55d950372cad15a5ccb2dfb50a6e568ac94b855f611ae25eea" }, { "path": "src/snapshots/linesweeper__tests__empty_horizontals.snap", "source_sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244", "source_git_blob": null, "sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244" }, { "path": "src/snapshots/linesweeper__tests__two_squares.snap", "source_sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846", "source_git_blob": null, "sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846" }, { "path": "src/snapshots/linesweeper__topology__tests__diamond.snap", "source_sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502", "source_git_blob": null, "sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502" }, diff --git a/vendor/linesweeper/src/lib.rs b/vendor/linesweeper/src/lib.rs index 7d2500d095..e1ebdad99b 100644 --- a/vendor/linesweeper/src/lib.rs +++ b/vendor/linesweeper/src/lib.rs @@ -267,6 +267,24 @@ mod tests { Topology::from_path(&path, 0.001).unwrap(); } + // Craft patch (add_bez_path error). + #[test] + fn add_bez_path_error_leaves_segments_unchanged() { + let mut segments = Segments::default(); + let open = BezPath::from_svg("M0,0 L10,0 L5,10 Z M20,0 L30,5 L25,10").unwrap(); + assert!(segments.add_bez_path(&open).is_err()); + assert_eq!(segments.len(), 0); + segments.check_invariants(); + + let square = BezPath::from_svg("M40,0 L50,0 L50,10 L40,10 Z").unwrap(); + segments.add_bez_path(&square).unwrap(); + segments.check_invariants(); + assert_eq!(segments.len(), 4); + let mut entered: Vec<_> = segments.entrances().iter().map(|(_, idx)| *idx).collect(); + entered.sort(); + assert_eq!(entered, segments.indices().collect::>()); + } + #[test] fn empty_paths() { let contours = binary_op( diff --git a/vendor/linesweeper/src/segments.rs b/vendor/linesweeper/src/segments.rs index 909eb01d2e..ae0e0c1def 100644 --- a/vendor/linesweeper/src/segments.rs +++ b/vendor/linesweeper/src/segments.rs @@ -298,9 +298,17 @@ impl Segments { /// Add a Bézier path to this arena. /// /// The path can contain multiple subpaths, and each of them must be closed. + /// If one of them is not closed, this returns an error and leaves the arena + /// unchanged. pub fn add_bez_path(&mut self, p: &BezPath) -> Result<(), NonClosedPath> { let old_len = self.segs.len(); - self.add_path_without_updating_enter_exit(p, true)?; + // Craft patch (add_bez_path error): segments pushed before the open + // subpath was found are removed, so no segment is left with a link + // past the end of the arena or without an entrance. + if let Err(e) = self.add_path_without_updating_enter_exit(p, true) { + self.truncate(old_len); + return Err(e); + } self.update_enter_exit(old_len); Ok(()) } @@ -407,6 +415,19 @@ impl Segments { self.segs.push(seg); } + // Craft patch (add_bez_path error): drops every segment at index `len` or + // above. `enter` and `exit` are left alone, so this is only for segments + // that `update_enter_exit` has not seen yet. + fn truncate(&mut self, len: usize) { + self.segs.inner.truncate(len); + self.horizontal_decomps.inner.truncate(len); + self.contour_prev.inner.truncate(len); + self.contour_next.inner.truncate(len); + self.orientation.inner.truncate(len); + self.split_from_predecessor.inner.truncate(len); + self.input_segs.inner.truncate(len); + } + /// Construct a segment arena from a single closed polyline. pub fn from_closed_polyline>(ps: impl IntoIterator) -> Self { let mut ret = Self::default();