Repository navigation
Validate MSF strings strictly, and stop cdio_read() at the last track - #121
Merged
Merged
Conversation
cdio_mmssff_to_lba() returned -1 instead of CDIO_INVALID_LBA when the frames field wasn't a digit, as in "00:00:x". Its callers only compare the result with CDIO_INVALID_LBA, so they accepted such a string as -1 sectors: as a FILE or DATAFILE length or START, PREGAP and SILENCE in a cdrdao TOC (71035b8 meant to reject invalid MSF strings there), and as INDEX and PREGAP in a CUE sheet. The minutes had no limit either, so a large value such as "954437:10:43" wrapped around to a negative LBA, and a longer string of digits overflowed an int. Return CDIO_INVALID_LBA for every error, and reject minutes whose LBA doesn't fit in an lba_t, which also stops the digits from overflowing. Minutes above 99 are still accepted: in a TOC file they can be an offset into a file longer than a CD, as test/data/t3.toc has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The length of a FILE or DATAFILE, in sectors, was multiplied by the sector size as an int before being compared with the size of the file. A length of more than about 900000 sectors, which an MSF string can now still give, overflowed it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_read_bincue() and _read_cdrdao() moved on to the next entry of tocent[] whenever the position reached its start, without checking that there was a next track. Past the last track they moved into the lead-out entry, which has a data size of 0, so the rest of the request never shrank and the position went on past the end of tocent[]. A cdio_read() of more than the image after cdio_lseek() read beyond the driver's data, and could take a sector size from there. The test for the next track also compared the position, which counts sectors from 0, with the track's start LBA, which includes the 150 sectors of the pregap, so the read moved on to the next track 150 sectors early. Stay in the last track, compare LBA with LBA, and stop when nothing is left of the current sector. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cdrdao test now gives START, PREGAP and SILENCE MSF strings whose frames or seconds aren't digits, whose seconds or frames are out of range, with too many digits, or whose LBA doesn't fit in an lba_t, and gives them as the length of a DATAFILE followed by another track. All must be rejected, while 180:00:00 and 477217:59:74 are still accepted. The bincue test does the same for INDEX and PREGAP. Both tests also read twice the size of the image with cdio_read() after seeking to its start. That only shows a difference under a memory checker such as valgrind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rocky
reviewed
Nov 17, 2026
| if('\0' != (c = *psz_mmssff++)) { | ||
| if (isdigit(c)) { | ||
| if(c >= '0' && c <= '9') { | ||
| psz_field = psz_field * 10 + (c - '0'); |
Contributor
There was a problem hiding this comment.
Another bug in the existing code, noticed in looking at this PR:
psz_field is an int, so a long string like 2147483648:00:00 can overflow psz_field * 10 + (c - '0').
Do you want to fix this in this PR, or leave it for another PR?
Collaborator
Author
There was a problem hiding this comment.
It's already covered by the previous checks. psz_field is capped at MAX_MMSSFF_MINUTES (477217) so it will never overflow at that point.
The largest possible value is: "477217:59:74"
Contributor
There was a problem hiding this comment.
Ok. My mistake. Thanks for checking.
Contributor
|
@Nicsp Thanks for the fixes, as before. LGTM. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes MSF strings in cdrdao TOC files and CUE sheets fully validated, and stops
cdio_read()on BIN/CUE and cdrdao images at the last track.What went wrong
cdio_mmssff_to_lba()returned-1instead ofCDIO_INVALID_LBAwhen the frames field wasn't a digit, as in00:00:x. Its callers only compare the result withCDIO_INVALID_LBA, so they accepted such a string as -1 sectors. That covers:954437:10:43wrapped around to a negative LBA, and a longer string of digits overflowed anint.intbefore comparing it with the file's size.cdio_read()went past the last track._read_bincue()and_read_cdrdao()moved to the nexttocent[]entry without checking that there was one. Past the last track they moved into the lead-out entry, whose data size is 0, so the request never shrank and they went on past the end oftocent[]. They also compared the position, which counts from 0, with a start LBA that includes the 150-sector pregap, so they changed track 150 sectors early.Changes
cdio_mmssff_to_lba()returnsCDIO_INVALID_LBAfor every error. It rejects minutes whose LBA doesn't fit in anlba_t, which also stops the digits from overflowing.test/data/t3.tocrelies on180:0:0parsing.off_t.cdio_read()stays in the last track, compares LBA with LBA, and stops when nothing is left of the current sector.Tests
lba_t. The same strings are also given as a DATAFILE length followed by another track. All must be rejected, while180:00:00and477217:59:74are still accepted.cdio_read()after seeking to its start. That part only shows a difference under a memory checker.make -C test checkandmake -C test/driver checkpass, and thebincueandcdrdaodriver tests are clean under valgrind. Without the library changes, the new MSF checks fail.🤖 Generated with Claude Code