From a2e6660596f4fca0c1b54df1bfd681494551ee25 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 8 Nov 2026 05:13:42 -0800 Subject: [PATCH] linesweeper: a ulp step past f64::MAX gives infinity instead of NaN F64Perturbation::apply tested the sign bit to detect an overflowing step, but the step reaches the infinity and NaN encodings first. It now compares the bits with the infinity encoding. --- NOTICE | 6 +++--- vendor/linesweeper/README.craft.md | 24 +++++++++++++++------- vendor/linesweeper/SOURCE.json | 6 ++++-- vendor/linesweeper/src/perturbation.rs | 28 +++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/NOTICE b/NOTICE index bd88d43e7a..3eadfd4366 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 local changes. 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 +changes 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..cca2fabe83 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -1,15 +1,25 @@ # 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 | +|---|---|---|---| +| A ulp step past `f64::MAX` in the test-only `F64Perturbation::apply` gives infinity; `Ulp(2)` of `f64::MAX` gave NaN | `Craft patch (ulp overflow)` | `src/perturbation.rs` | `ulp_step_past_f64_max_is_infinite` | + +Every change here updates this table and `SOURCE.json` in the same commit. To take a new linesweeper +release, unpack the crates.io package, carry these changes over, regenerate `SOURCE.json`, and run the +tests below. `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..5d942a5dcb 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": [ + "`F64Perturbation::apply` clamps a ulp step on a normal value to infinity when the bits reach the infinity encoding, instead of testing the sign bit, so `Ulp(2)` of `f64::MAX` gives infinity instead of NaN." + ], "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" }, @@ -40,7 +42,7 @@ { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6" }, { "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/perturbation.rs", "source_sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5", "source_git_blob": null, "sha256": "86c27289a9e447a7a1022d3a5c35cf85490555a8904f28bc90a479dcbd49d4ca" }, { "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/snapshots/linesweeper__tests__empty_horizontals.snap", "source_sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244", "source_git_blob": null, "sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244" }, diff --git a/vendor/linesweeper/src/perturbation.rs b/vendor/linesweeper/src/perturbation.rs index ffb4aea5e4..ff814b822b 100644 --- a/vendor/linesweeper/src/perturbation.rs +++ b/vendor/linesweeper/src/perturbation.rs @@ -60,7 +60,10 @@ impl FloatPerturbation for F64Perturbation { // Taking the absolute value sets the sign bit to zero, so the // addition should never overflow. let bits = f.abs().to_bits().checked_add_signed(delta).unwrap(); - let x = if bits & sign_bit != 0 { + // Craft patch (ulp overflow): a step past `f64::MAX` reaches the + // infinity and NaN encodings, not the sign bit, so it is clamped to + // infinity there. + let x = if bits >= f64::INFINITY.to_bits() { f64::INFINITY } else { f64::from_bits(bits) @@ -198,3 +201,26 @@ pub fn realize_perturbation( } } } + +// Craft patch (ulp overflow). +#[cfg(test)] +mod ulp_overflow_tests { + use super::*; + + #[test] + fn ulp_step_past_f64_max_is_infinite() { + for (n, f, expected) in [ + (2, f64::MAX, f64::INFINITY), + (127, f64::MAX, f64::INFINITY), + (-2, -f64::MAX, f64::NEG_INFINITY), + (1, f64::from_bits(f64::MAX.to_bits() - 1), f64::MAX), + (-1, f64::MAX, f64::from_bits(f64::MAX.to_bits() - 1)), + ] { + assert_eq!( + F64Perturbation::Ulp(n).apply(&f), + expected, + "Ulp({n}) of {f}" + ); + } + } +}