+cpmtools (2.23-6) unstable; urgency=low
+
+ * patch from Jacob Nevins for libdsk probe robustness expected to be in
+ 2.24 when released, closes: #1079619
+
+ -- Bdale Garbee <bdale@gag.com> Thu, 26 Sep 2024 20:46:26 -0600
+
cpmtools (2.23-5) unstable; urgency=low
* elide processed man pages from repo, ensure they're removed in
--- /dev/null
+Subject: libdsk: reset geometry if autoprobe isn't sane
+
+So that weirdness from any misfiring auto-geometry heuristic in LibDsk
+doesn't cause trouble later. (We were overwriting the most common
+parameters, but not all of them.)
+(Triggered by Debian bug #1079619, where a spurious dg_sidedness caused
+trouble after LibDsk's Opus Discovery heuristic misfired -- that
+heuristic has been improved in libdsk 1.5.20, but this change provides
+defence in depth.)
+---
+ device_libdsk.c | 18 +++++++++++++++---
+ 1 file changed, 15 insertions(+), 3 deletions(-)
+
+diff --git a/device_libdsk.c b/device_libdsk.c
+index 7baaed4..82b79d1 100644
+--- a/device_libdsk.c
++++ b/device_libdsk.c
+@@ -72,6 +72,7 @@ const char *Device_open(struct Device *this, const char *filename, int mode, con
+ const char *Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks, off_t offset, const char *libdskGeometry)
+ {
+ char *boo;
++ int probeOk;
+
+ this->secLength=secLength;
+ this->sectrk=sectrk;
+@@ -85,11 +86,22 @@ const char *Device_setGeometry(struct Device *this, int secLength, int sectrk, i
+ return lookupFormat(&this->geom, libdskGeometry);
+ }
+
++ /* Did the autoprobe guess right about the number of sectors & cylinders? */
++ if (this->geom.dg_cylinders * this->geom.dg_heads == tracks)
++ {
++ probeOk = 1;
++ }
++ else
++ {
++ /* If not, reset to a minimal geometry (to undo any randomness from
++ * a failed autoprobe), and guess some parameters */
++ probeOk = 0;
++ dg_stdformat(&this->geom, FMT_180K, NULL, NULL);
++ }
+ this->geom.dg_secsize = secLength;
+ this->geom.dg_sectors = sectrk;
+- /* Did the autoprobe guess right about the number of sectors & cylinders? */
+- if (this->geom.dg_cylinders * this->geom.dg_heads == tracks) return NULL;
+- /* Otherwise we guess: <= 43 tracks: single-sided. Else double. This
++ if (probeOk) return NULL;
++ /* We guess: <= 43 tracks: single-sided. Else double. This
+ * fails for 80-track single-sided if there are any such beasts */
+ if (tracks <= 43)
+ {
+--
+2.30.2
+