Skip to content

Image drivers: check track numbers, and free values given again - #122

Open
nicosp wants to merge 6 commits into
libcdio:mainfrom
nicosp:image-driver-fixes
Open

nicosp wants to merge 6 commits into
libcdio:mainfrom
nicosp:image-driver-fixes

Conversation

@nicosp

@nicosp nicosp commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Fixes in the bincue, cdrdao and NRG image drivers for track numbers and for values that were leaked.

Track numbers

  • The track getters shared by the three drivers (channels, copy permit, pre-emphasis, pregap, ISRC) used the track number as an index into the table of tracks without checking it. A disc whose only track is 99 read tocent[-98] for track 1. They now return their error value for a track the image doesn't have.
  • bincue only logged a track number that didn't follow the previous one. Tracks 99, 2 and 3 gave a disc whose last track is 101. This is now an error, so the last track is at most 99.

Leaks

  • bincue: the BIN file named by FILE replaced the "source" argument without freeing it, on every successful open. A FILE, CATALOG or ISRC given twice leaked the first value.
  • cdrdao: FILE/AUDIOFILE/DATAFILE given twice in a track leaked the file name and left the first file open; CATALOG and ISRC given twice leaked the first value. When a TOC file failed to parse, none of the tracks read so far were freed.
  • NRG: a second DAOX/DAOI chunk leaked the MCN and the ISRCs, and a second CDTX chunk the first CD-TEXT. A failed MCN allocation leaked the footer buffer, and a failed ISRC allocation wasn't checked.

Every freed value is replaced right away or freed once on close; the repeated keywords and failure paths were run under ASan to check for double frees.

Tests
New checks in test/driver/bincue.c and test/driver/cdrdao.c. With the old code the bincue test crashes in the track getters; the leaks only show under a memory checker. make check passes, and the bincue, cdrdao and nrg driver tests are clean under valgrind.

🤖 Generated with Claude Code

nicosp and others added 6 commits November 17, 2026 17:57
The track getters shared by the bincue, cdrdao and NRG drivers
(channels, copy permit, pre-emphasis, pregap and ISRC) used the track
number as an index into the table of tracks without checking it. The
public wrappers only check it against the last track, or not at all, so
a disc whose first track is 99 read tocent[-98] for track 1.

Check that the track is between the first and the last track, and
return the getter's error value otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A track number that didn't follow the previous one was only logged,
and the tracks were still numbered from the first one. A cue sheet
with tracks 99, 2 and 3 gave a disc whose last track is 101, past the
99 tracks a CD can have and that callers size their tables for; track
170 would be taken for the lead-out.

Make it an error, also when only checking whether a file is a cue
sheet. Since each track number is at most 99, so is the last one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bincue: the BIN file named by FILE replaced the "source" argument set
when the image is opened without freeing it, on every successful
open. A second FILE in a track, CATALOG or ISRC leaked the first value
too.

nrg: a second DAOX or DAOI chunk leaked the MCN and the tracks' ISRCs,
and a second CDTX chunk the first CD-TEXT. A failed MCN allocation
leaked the footer buffer, and a failed ISRC allocation wasn't checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second FILE, AUDIOFILE or DATAFILE in a track leaked the first file
name and left the first file open, and a second CATALOG or ISRC leaked
the first value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The number of tracks was only set once the whole file had parsed, so
when a later line failed, the cleanup freed none of the earlier
tracks' file names, ISRCs and open files.

Set it on the error path too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bincue: the track getters on a disc whose only track is 99, tracks
whose numbers don't follow each other, and CATALOG, FILE and ISRC given
twice. cdrdao: CATALOG, ISRC and FILE/DATAFILE given twice, and a TOC
file that fails after its first track.

The leaks these used to cause only show under a memory checker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicosp
nicosp requested a review from rocky November 17, 2026 16:02
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