Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for lsn errors on span processing to avoid issues with track 0 on CDs without hidden track #39

Merged
merged 7 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/cdda_interface/toc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cdda_track_firstsector(cdrom_drive_t *d, track_t i_track)
}
}

/*! Get first lsn of the first audio track. -1 is returned on error. */
/*! Get first lsn of the first audio track. -ERROR_CODE is returned on error. */
lsn_t
cdda_disc_firstsector(cdrom_drive_t *d)
{
Expand All @@ -87,7 +87,7 @@ cdda_disc_firstsector(cdrom_drive_t *d)
}

/*! Get last lsn of the track. The lsn is generally one less than the
start of the next track. -1 is returned on error. */
start of the next track. -ERROR_CODE is returned on error. */
lsn_t
cdda_track_lastsector(cdrom_drive_t *d, track_t i_track)
{
Expand Down Expand Up @@ -129,7 +129,7 @@ cdda_track_lastsector(cdrom_drive_t *d, track_t i_track)
}

/*! Get last lsn of the last audio track. The last lssn generally one
less than the start of the next track after the audio track. -1 is
less than the start of the next track after the audio track. -ERROR_CODE is
returned on error. */
lsn_t
cdda_disc_lastsector(cdrom_drive_t *d)
Expand All @@ -149,7 +149,7 @@ cdda_disc_lastsector(cdrom_drive_t *d)
return -403;
}

/*! Return the number of tracks on the or 300 if error. */
/*! Return the number of tracks on the CD or CDIO_INVALID_TRACK (255) if error. */
track_t
cdda_tracks(cdrom_drive_t *d)
{
Expand Down
51 changes: 34 additions & 17 deletions src/cd-paranoia.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,11 +1226,19 @@ main(int argc,char *argv[])
}

{
int track1 = cdda_sector_gettrack(d, i_first_lsn);
/* Check for errors on lsn before getting track */
if(i_first_lsn < 0){
report("Error on begin of span: %li. Aborting.\n\n", i_first_lsn);
exit(1);
}
if(i_last_lsn < 0 ){
report("Error on end of span: %li. Aborting.\n\n", i_last_lsn);
exit(1);
}

int track1 = cdda_sector_gettrack(d, i_first_lsn);
int track2 = cdda_sector_gettrack(d, i_last_lsn);
long off1 = i_first_lsn - cdda_track_firstsector(d, track1);
long off2 = i_last_lsn - cdda_track_firstsector(d, track2);

int i;

for( i=track1; i<=track2; i++ ) {
Expand All @@ -1240,6 +1248,9 @@ main(int argc,char *argv[])
}
}

long off1 = i_first_lsn - cdda_track_firstsector(d, track1);
long off2 = i_last_lsn - cdda_track_firstsector(d, track2);

report("Ripping from sector %7ld (track %2d [%d:%02d.%02d])\n"
"\t to sector %7ld (track %2d [%d:%02d.%02d])\n",
i_first_lsn,
Expand Down Expand Up @@ -1341,30 +1352,36 @@ main(int argc,char *argv[])
exit(1);
}

int res;
if(batch) {
if (strlen(argv[optind+1]) - 10 > PATH_MAX) {
report("Output filename too long");
exit(1);
}
snprintf(outfile_name, PATH_MAX,
res=snprintf(outfile_name, PATH_MAX,
" %strack%02d.%s", dirname,
batch_track, basename);
} else
snprintf(outfile_name, PATH_MAX, "%s%s", dirname, basename);
res=snprintf(outfile_name, PATH_MAX, "%s%s", dirname, basename);

if(res < 0){
report("Error on setting filename");
exit(1);
}
if(res >= PATH_MAX){
report("Output filename too long");
exit(1);
}

if(basename[0]=='\0'){
switch (output_type) {
case 0: /* raw */
strncat(outfile_name, "cdda.raw", sizeof("cdda.raw"));
strncat(outfile_name, "cdda.raw", PATH_MAX - strlen(outfile_name) - 1);
break;
case 1:
strncat(outfile_name, "cdda.wav", sizeof("cdda.wav"));
strncat(outfile_name, "cdda.wav", PATH_MAX - strlen(outfile_name) - 1);
break;
case 2:
strncat(outfile_name, "cdda.aifc", sizeof("cdda.aifc"));
strncat(outfile_name, "cdda.aifc", PATH_MAX - strlen(outfile_name) - 1);
break;
case 3:
strncat(outfile_name, "cdda.aiff", sizeof("cdda.aiff"));
strncat(outfile_name, "cdda.aiff", PATH_MAX - strlen(outfile_name) - 1);
break;
}
}
Expand All @@ -1390,16 +1407,16 @@ main(int argc,char *argv[])

switch(output_type){
case 0: /* raw */
strncat(outfile_name, "cdda.raw", sizeof("cdda.raw"));
strncat(outfile_name, "cdda.raw", PATH_MAX - strlen(outfile_name) - 1);
break;
case 1:
strncat(outfile_name, "cdda.wav", sizeof("cdda.wav"));
strncat(outfile_name, "cdda.wav", PATH_MAX - strlen(outfile_name) - 1);
break;
case 2:
strncat(outfile_name, "cdda.aifc", sizeof("cdda.aifc"));
strncat(outfile_name, "cdda.aifc", PATH_MAX - strlen(outfile_name) - 1);
break;
case 3:
strncat(outfile_name, "cdda.aiff", sizeof("cdda.aiff"));
strncat(outfile_name, "cdda.aiff", PATH_MAX - strlen(outfile_name) - 1);
break;
}

Expand Down
Loading