Skip to content

Conversation

@wizzomafizzo
Copy link
Member

Summary

Add comprehensive CHD (Compressed Hunks of Data) V5 format support for game identification across all disc-based consoles.

  • New chd package with full CHD V5 parsing
  • Support for all common codecs: zlib, LZMA, FLAC, Zstandard
  • Integration with existing disc-based identifiers (PSX, PS2, PSP, Saturn, Sega CD, Neo Geo CD, GameCube)
  • DoS protection via allocation limits
  • Tested against 648 real CHD files with 100% success rate

Changes

New Package: chd/

  • header.go - CHD V5 header parsing
  • hunk.go - Hunk map parsing and caching
  • metadata.go - Track metadata (CHT2, CHTR, CHCD formats)
  • codec_*.go - Compression codec implementations
  • bitstream.go - Huffman decoder for V5 maps
  • errors.go - Error types and allocation limits

Modified Files

  • iso9660/iso9660.go - Refactored to use io.ReaderAt for CHD compatibility
  • iso9660/chd.go - New adapter for CHD→ISO9660
  • console.go - CHD detection logic
  • identifier/*.go - Added .chd extension support to all disc identifiers

Dependencies

  • github.com/klauspost/compress - Zstandard
  • github.com/mewkiz/flac - FLAC
  • github.com/ulikunitz/xz - LZMA (v0.5.15, patched for GO-2025-3922)

Test plan

  • All existing tests pass (make check)
  • New CHD tests with 240pSuite test files
  • Manual testing against 648 real CHD files (516 PSX, 82 Saturn, 50 Sega CD)
  • govulncheck passes (LZMA vulnerability fixed)

Add comprehensive CHD (Compressed Hunks of Data) V5 format support for
game identification across all disc-based consoles: PSX, PS2, PSP,
Saturn, Sega CD, Neo Geo CD, and GameCube.

New chd package features:
- Full CHD V5 header and hunk map parsing
- Codec support: zlib (cdzl), LZMA (cdlz), FLAC (cdfl), Zstandard (cdzs)
- Bitstream reader for Huffman-encoded hunk maps
- Track metadata parsing (CHT2, CHTR, CHCD formats)
- Sector readers for both raw (2352-byte) and ISO (2048-byte) access
- Automatic data track detection for multi-track CDs
- Hunk caching for performance
- DoS protection via allocation limits (MaxNumHunks, MaxCompMapLen, etc.)
- Circular metadata chain detection

Integration:
- iso9660 package refactored to use io.ReaderAt for CHD compatibility
- New iso9660.OpenCHD() adapter for seamless filesystem access
- All disc-based identifiers updated with .chd extension support
- Console detection via raw sector magic bytes and ISO9660 analysis

Tested against 648 real CHD files with 100% identification success rate
(516 PSX, 82 Saturn, 50 Sega CD).
@codecov
Copy link

codecov bot commented Dec 10, 2025

Add comprehensive unit tests covering:
- CHD codecs (zlib, lzma decompression and error handling)
- CHD header parsing (V3/V4 formats)
- CHD metadata parsing (CHTR, CHCD formats)
- CHD circular metadata chain detection
- ISO9660 OpenCHD, OpenReaderWithCloser, GetDataPreparerID
- Console detection from CHD files (SegaCD, NeoGeoCD, GameCube)
- IdentifyFromReader function
- identifyFromDirectory for disc-based and cartridge consoles

Also add nolint directives for gosec G602 false positives in
codec_lzma.go and codec_zlib.go where bounds are already validated.

Coverage improved from ~61% to 65.9% overall.
@wizzomafizzo wizzomafizzo merged commit 0a28cb3 into main Dec 10, 2025
9 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.

2 participants