Skip to content

fix: handle disc identification edge cases#12

Merged
wizzomafizzo merged 4 commits into
mainfrom
fix/disc-identification-edge-cases
Jul 6, 2026
Merged

fix: handle disc identification edge cases#12
wizzomafizzo merged 4 commits into
mainfrom
fix/disc-identification-edge-cases

Conversation

@wizzomafizzo

@wizzomafizzo wizzomafizzo commented Jul 6, 2026

Copy link
Copy Markdown
Member

Summary

  • fall back from path-based GameCube handling to reader identification for plain files
  • improve PlayStation serial extraction and DB-confirmed filename fallback
  • harden ISO9660/Sega CD/SNES parsing against malformed data and cap ISO file reads
  • update 2026 license headers and lint cleanups

Tests

  • go test ./...
  • make lint

Summary by CodeRabbit

  • Bug Fixes
    • Improved identification for path-based sources, with more reliable fallback when direct path scanning isn’t supported.
    • Enhanced PlayStation disc serial detection from root filenames, with stricter filename-based fallback when catalog data is available.
    • Added bounds-safety for Sega CD and SNES parsing to avoid issues with malformed inputs.
    • Improved ISO handling for block-device inputs and added limits to prevent unsafe allocations when reading directory entries.
  • Maintenance
    • Updated copyright headers and clarified byte handling in a few encoding-related paths.
    • Updated the build/test Go toolchain version.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d73518a-9ef5-4906-9b81-065f82c21e5b

📥 Commits

Reviewing files that changed from the base of the PR and between b162512 and f674af0.

📒 Files selected for processing (4)
  • .github/workflows/release.yml
  • gameid.go
  • iso9660/iso9660.go
  • iso9660/iso9660_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • iso9660/iso9660.go
  • iso9660/iso9660_test.go
  • gameid.go

📝 Walkthrough

Walkthrough

This PR updates copyright headers from 2025 to 2026 across most repository files. It also changes path-identification fallback behavior, improves PlayStation serial extraction, adds bounds checks in Sega CD/SNES parsing, adjusts CHD byte masking, removes lint suppressions, updates ISO9660 block-device handling and read-size limits, simplifies one N64 test helper, and bumps the Go toolchain version.

Changes

Functional and safety fixes

Layer / File(s) Summary
Path identification fallback
gameid.go, gameid_test.go
IdentifyWithConsole and identifyFromBlockDevice now fall back only when IdentifyFromPath returns identifier.NotSupportedError; a GameCube plain-file test was added.
PlayStation serial extraction
identifier/psx.go, identifier/psx_test.go
Adds root-filename serial parsing, limits filename fallback to database-confirmed candidates, and updates tests for the new serial and fallback behavior.
Sega CD and SNES bounds safety
identifier/segacd.go, identifier/segacd_test.go, identifier/snes.go
Adds header/index bounds checks before slicing or reading, plus a Sega CD near-end-of-header test.
CHD byte masking
chd/codec.go, chd/codec_flac.go, chd/chd_test.go
Shifted byte extraction now masks with & 0xFF, and the CHD test uses the same byte construction.
Lint suppression removals
archive/rar.go, chd/codec_lzma.go, chd/codec_zlib.go
Removes //nolint comments without changing the surrounding logic.
ISO9660 block device handling
iso9660/iso9660.go, iso9660/iso9660_test.go
Open detects block devices, init uses a helper for block-size detection, and ReadFile rejects oversized claimed file sizes; tests cover both paths.
N64 test helper simplification
identifier/n64_test.go
The ROM title helper now uses space padding plus an exact 20-byte copy.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Copyright Year Updates

Layer / File(s) Summary
Header year updates
archive/*, chd/*, identifier/*, iso9660/*, internal/binary/*, blockdevice_unix.go, console.go, console_test.go, database.go, database_test.go, cmd/dbgen/main.go, cmd/gameid/main.go
Copyright year comments were updated from 2025 to 2026 with no functional changes.

Toolchain Update

Layer / File(s) Summary
Go directive update
go.mod, .github/workflows/release.yml
The Go version used by the module and release build was updated to 1.26.4.

Related Issues: Not specified.

Related PRs: Not specified.

Suggested labels: enhancement, bug, chore

Suggested reviewers: Not specified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: fixing disc identification edge cases across multiple formats.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 fix/disc-identification-edge-cases

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

@wizzomafizzo wizzomafizzo changed the title Fix disc identification edge cases fix: handle disc identification edge cases Jul 6, 2026
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.78788% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gameid.go 42.85% 9 Missing and 3 partials ⚠️
iso9660/iso9660.go 66.66% 6 Missing and 1 partial ⚠️
chd/codec_flac.go 77.77% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
iso9660/iso9660.go (1)

397-407: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Solid bounds check; consider exposing the cap if reuse beyond identification is anticipated.

The size check and error wrapping are correct and well-documented. maxReadFileSize is currently private and fixed at 16MiB — fine for the current identification-only use case, but if ReadFile is later used to extract full game files elsewhere in the codebase, this cap could unexpectedly reject legitimate larger reads.

🤖 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 `@iso9660/iso9660.go` around lines 397 - 407, The size guard in ReadFile is
correct, but maxReadFileSize is a private fixed limit that may block future
legitimate callers; update the ISO9660 package to make the read cap configurable
or exported so reuse beyond identification can adjust it as needed, and keep
ReadFile using that shared limit constant/value.
gameid.go (1)

291-302: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate error-handling pattern; consider extracting a shared helper.

This block repeats the same IdentifyFromPatherrors.As(identifier.NotSupportedError) fallback pattern as Lines 141-154. The same type-matching concern raised there applies here as well. Extracting a small helper (e.g., identifyFromPathOrFallback or an isNotSupported(err) bool predicate) would avoid the two call sites silently diverging if the contract changes later.

♻️ Example helper extraction
+func isNotSupportedErr(err error) bool {
+	var notSupported identifier.NotSupportedError
+	return errors.As(err, &notSupported)
+}
+
 func identifyFromBlockDevice(path string, _ Console, ident identifier.Identifier, database identifier.Database) (*Result, error) {
 	if pid, ok := ident.(pathIdentifier); ok {
 		result, err := pid.IdentifyFromPath(path, database)
 		if err == nil {
 			return result, nil
 		}
-		var notSupported identifier.NotSupportedError
-		if !errors.As(err, &notSupported) {
+		if !isNotSupportedErr(err) {
 			return nil, fmt.Errorf("identify from path: %w", err)
 		}
 	}
🤖 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 `@gameid.go` around lines 291 - 302, This block duplicates the IdentifyFromPath
fallback logic already used elsewhere, so extract the shared error-handling into
a helper to keep both call sites consistent. Move the path-based identification
and identifier.NotSupportedError check into a small reusable function or
predicate (for example, one used by gameID identification flow in gameid.go),
then update this branch to call that helper and preserve the current
fallback-to-raw-block-device behavior only when the error is NotSupported.
🤖 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.

Nitpick comments:
In `@gameid.go`:
- Around line 291-302: This block duplicates the IdentifyFromPath fallback logic
already used elsewhere, so extract the shared error-handling into a helper to
keep both call sites consistent. Move the path-based identification and
identifier.NotSupportedError check into a small reusable function or predicate
(for example, one used by gameID identification flow in gameid.go), then update
this branch to call that helper and preserve the current
fallback-to-raw-block-device behavior only when the error is NotSupported.

In `@iso9660/iso9660.go`:
- Around line 397-407: The size guard in ReadFile is correct, but
maxReadFileSize is a private fixed limit that may block future legitimate
callers; update the ISO9660 package to make the read cap configurable or
exported so reuse beyond identification can adjust it as needed, and keep
ReadFile using that shared limit constant/value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e7e86d2b-fba1-4388-8f32-b5dee5c5c2bf

📥 Commits

Reviewing files that changed from the base of the PR and between 2916d33 and 0b6de1a.

📒 Files selected for processing (71)
  • archive/archive.go
  • archive/archive_test.go
  • archive/detect.go
  • archive/detect_test.go
  • archive/errors.go
  • archive/errors_test.go
  • archive/path.go
  • archive/path_test.go
  • archive/rar.go
  • archive/sevenzip.go
  • archive/zip.go
  • blockdevice_unix.go
  • chd/bitstream.go
  • chd/chd.go
  • chd/chd_test.go
  • chd/codec.go
  • chd/codec_flac.go
  • chd/codec_lzma.go
  • chd/codec_zlib.go
  • chd/codec_zstd.go
  • chd/errors.go
  • chd/header.go
  • chd/hunk.go
  • chd/metadata.go
  • cmd/dbgen/main.go
  • cmd/gameid/main.go
  • console.go
  • console_test.go
  • database.go
  • database_test.go
  • gameid.go
  • gameid_test.go
  • identifier/fuzz_test.go
  • identifier/gb.go
  • identifier/gb_test.go
  • identifier/gba.go
  • identifier/gba_test.go
  • identifier/gc.go
  • identifier/gc_test.go
  • identifier/genesis.go
  • identifier/genesis_test.go
  • identifier/identifier.go
  • identifier/n64.go
  • identifier/n64_test.go
  • identifier/neogeocd.go
  • identifier/neogeocd_test.go
  • identifier/nes.go
  • identifier/nes_test.go
  • identifier/ps2.go
  • identifier/ps2_test.go
  • identifier/psp.go
  • identifier/psp_test.go
  • identifier/psx.go
  • identifier/psx_test.go
  • identifier/saturn.go
  • identifier/saturn_test.go
  • identifier/segacd.go
  • identifier/segacd_test.go
  • identifier/snes.go
  • identifier/snes_test.go
  • internal/binary/fuzz_test.go
  • internal/binary/reader.go
  • internal/binary/reader_test.go
  • iso9660/chd.go
  • iso9660/cue.go
  • iso9660/cue_test.go
  • iso9660/fuzz_test.go
  • iso9660/iso9660.go
  • iso9660/iso9660_test.go
  • iso9660/mounted.go
  • iso9660/mounted_test.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@go.mod`:
- Line 3: The release workflow is still using an older Go version than the
module requires, so update the Go setup in the release pipeline to match the
version declared in go.mod. Find the Go version configuration in the release
workflow and change it to the same 1.26.4-compatible version used by the module
so release builds use the correct toolchain.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: adf48302-c8ea-4386-ad89-dbf5a0f896e6

📥 Commits

Reviewing files that changed from the base of the PR and between 0b6de1a and b162512.

📒 Files selected for processing (1)
  • go.mod

Comment thread go.mod
@wizzomafizzo
wizzomafizzo merged commit 5e81fb0 into main Jul 6, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant