dvd-sector-copy.c: Calculate the clear-area size consistently.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 8 Apr 2022 17:24:22 +0000 (18:24 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 Apr 2022 17:24:22 +0000 (18:24 +0100)
This should be determined as a (possibly fractional) multiple of the
distance from the start of the bad region to the current position.
Alas, the code for the bounding stage incorrectly used the distance from
the previous position to the new one.  The inconsistency between the
bounding and refinement stages of the recovery algorithm could lead to
failed invariants and a nonsense result.

dvd-sector-copy.c

index 73e068a..40ee26d 100644 (file)
@@ -743,8 +743,8 @@ static ssize_t find_good_sector(secaddr *pos_inout, secaddr end,
     step = (step_factor - 1)*(bad_hi - bad_lo);
     if (step < step_min) step = step_min;
     if (step_max && step > step_max) step = step_max;
-    if (step > end - bad_hi) step = end - bad_hi;
-    pos = bad_hi + step - 1;
+    step += bad_hi - bad_lo;
+    if (step > end - bad_lo) step = end - bad_lo;
     want = run_length_wanted(pos, step, end);
     n = recovery_read(&r, pos, want);
 #ifdef DEBUG