Skip to content

Adding correction to the iec-60908b code.#2028

Merged
nicolasnoble merged 1 commit into
mainfrom
forney
Jun 4, 2026
Merged

Adding correction to the iec-60908b code.#2028
nicolasnoble merged 1 commit into
mainfrom
forney

Conversation

@nicolasnoble

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds a Mode 2 CD sector corrector that validates and repairs Yellow Book EDC/ECC using Galois-field arithmetic. It introduces helpers for GF operations and symbol addressing, implements Reed-Solomon line correction, adds EDC verification via CRC32, and orchestrates repair by iteratively correcting P and Q lines until the sector passes EDC validation.

Changes

CD Sector Error Correction

Layer / File(s) Summary
Public API contract
third_party/iec-60908b/correct.h
Declares check_edc() for EDC verification and correct_sector() for in-place Mode 2 sector repair.
Galois-field and addressing infrastructure
third_party/iec-60908b/correct.c
GF multiplication/division via log/exp tables with zero-handling; P- and Q-line symbol-to-byte address mapping for different k ranges.
Reed-Solomon line correction
third_party/iec-60908b/correct.c
Single-line (n, n-2) correction: computes syndromes, derives error locator via GF division, bounds-checks, and applies XOR correction to target symbol.
EDC validation
third_party/iec-60908b/correct.c
Recomputes Yellow Book CRC32 over form-dependent byte ranges and compares against stored EDC; returns early success for non-Mode-2 sectors.
Main correction orchestration
third_party/iec-60908b/correct.c
Blanks/restores header bytes, iteratively applies P then Q line corrections in repeated passes, re-checks EDC after each pass, stops on validation success or stalled progress, returns final EDC result.

🎯 3 (Moderate) | ⏱️ ~25 minutes

A rabbit hops through galois fields so fine,
With P and Q lines dancing in perfect design,
Each error erased by the XOR's keen hand,
'til EDC sings true—oh, what beautifully repaired land! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether any description content relates to the changeset. Add a pull request description explaining the purpose and functionality of the EDC/ECC correction implementation for Mode 2 CD sectors.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main changeset, which adds EDC/ECC correction functionality to the IEC 60908 CD sector handling code.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch forney

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@third_party/iec-60908b/correct.c`:
- Around line 151-158: The code currently reads the form bit from subheader[2]
into form and returns 0 for form==2 immediately after a failed
check_edc(sector), which incorrectly skips ECC repair if that form bit is
corrupted; instead, after check_edc(sector) fails, do not short-circuit on the
subheader bit—attempt the ECC repair path used for Form 1 (i.e., invoke the
module’s ECC correction routine on sector) even when (subheader[2] & 0x20) is
set, and only treat the sector as unrecoverable if ECC correction also fails;
keep the original form value for post-repair validation but do not use it to
prevent attempting ECC correction (reference: subheader, form, check_edc and the
project’s ECC correction function).

In `@third_party/iec-60908b/correct.h`:
- Line 5: Update the license header year from 2026 to 2025 in the third-party
IEC-60908b sources: replace the line that currently reads "Copyright (c) 2026
Nicolas \"Pixel\" Noble" with the same text using 2025 in both the header and
the corresponding source file (the identical copyright block in correct.h and
correct.c).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a4b8b23a-58bf-4035-86a6-01f518a251a7

📥 Commits

Reviewing files that changed from the base of the PR and between d658f89 and 198c9ca.

📒 Files selected for processing (2)
  • third_party/iec-60908b/correct.c
  • third_party/iec-60908b/correct.h

Comment on lines +151 to +158
const uint8_t* subheader = body + 4;
unsigned form = (subheader[2] & 0x20) ? 2 : 1;

// A clean sector needs no work, and Form 2 has no ECC at all, so for Form 2
// the EDC verdict is final either way.
if (check_edc(sector)) return 1;
if (form == 2) return 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t gate ECC repair on a single potentially corrupted form bit.

form is derived only from subheader[2], then if (form == 2) return 0; skips correction entirely. If a Form 1 sector has that bit flipped, this returns failure without attempting recoverable ECC repair.

Suggested hardening
-    const uint8_t* subheader = body + 4;
-    unsigned form = (subheader[2] & 0x20) ? 2 : 1;
+    const uint8_t* subheader = body + 4;
+    unsigned form_a = (subheader[2] & 0x20) ? 2 : 1;  // first subheader copy
+    unsigned form_b = (subheader[6] & 0x20) ? 2 : 1;  // duplicated copy

     // A clean sector needs no work, and Form 2 has no ECC at all, so for Form 2
     // the EDC verdict is final either way.
     if (check_edc(sector)) return 1;
-    if (form == 2) return 0;
+    // Only treat as Form 2 when both copies agree; otherwise bias to Form 1 path
+    // so ECC still gets a chance to recover a damaged Form 1 subheader.
+    if (form_a == 2 && form_b == 2) return 0;
+    unsigned form = 1;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const uint8_t* subheader = body + 4;
unsigned form = (subheader[2] & 0x20) ? 2 : 1;
// A clean sector needs no work, and Form 2 has no ECC at all, so for Form 2
// the EDC verdict is final either way.
if (check_edc(sector)) return 1;
if (form == 2) return 0;
const uint8_t* subheader = body + 4;
unsigned form_a = (subheader[2] & 0x20) ? 2 : 1; // first subheader copy
unsigned form_b = (subheader[6] & 0x20) ? 2 : 1; // duplicated copy
// A clean sector needs no work, and Form 2 has no ECC at all, so for Form 2
// the EDC verdict is final either way.
if (check_edc(sector)) return 1;
// Only treat as Form 2 when both copies agree; otherwise bias to Form 1 path
// so ECC still gets a chance to recover a damaged Form 1 subheader.
if (form_a == 2 && form_b == 2) return 0;
unsigned form = 1;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@third_party/iec-60908b/correct.c` around lines 151 - 158, The code currently
reads the form bit from subheader[2] into form and returns 0 for form==2
immediately after a failed check_edc(sector), which incorrectly skips ECC repair
if that form bit is corrupted; instead, after check_edc(sector) fails, do not
short-circuit on the subheader bit—attempt the ECC repair path used for Form 1
(i.e., invoke the module’s ECC correction routine on sector) even when
(subheader[2] & 0x20) is set, and only treat the sector as unrecoverable if ECC
correction also fails; keep the original form value for post-repair validation
but do not use it to prevent attempting ECC correction (reference: subheader,
form, check_edc and the project’s ECC correction function).


MIT License

Copyright (c) 2026 Nicolas "Pixel" Noble

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the repository’s expected copyright year in the license header.

This header uses 2026, but project convention here is 2025; please align this line (and the same license block in third_party/iec-60908b/correct.c).

Suggested patch
-Copyright (c) 2026 Nicolas "Pixel" Noble
+Copyright (c) 2025 Nicolas "Pixel" Noble
Based on learnings: The current year for the PCSX-Redux project is 2025, and copyright notices should reflect this year.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Copyright (c) 2026 Nicolas "Pixel" Noble
Copyright (c) 2025 Nicolas "Pixel" Noble
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@third_party/iec-60908b/correct.h` at line 5, Update the license header year
from 2026 to 2025 in the third-party IEC-60908b sources: replace the line that
currently reads "Copyright (c) 2026 Nicolas \"Pixel\" Noble" with the same text
using 2025 in both the header and the corresponding source file (the identical
copyright block in correct.h and correct.c).

@nicolasnoble nicolasnoble merged commit 4bdfe1d into main Jun 4, 2026
21 of 22 checks passed
@nicolasnoble nicolasnoble deleted the forney branch June 4, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant