From d80e38943fceaeb3c3e8c10033bb9e5c9dd74752 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 17:57:10 +0200 Subject: [PATCH 1/6] image: return an error for a track the image doesn't have 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 --- lib/driver/image_common.c | 45 +++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/driver/image_common.c b/lib/driver/image_common.c index 0c55c9ce..c5281ac3 100644 --- a/lib/driver/image_common.c +++ b/lib/driver/image_common.c @@ -241,6 +241,17 @@ _get_track_msf_image(void *p_user_data, track_t i_track, msf_t *msf) return false; } +/* Return the tocent[] entry of track number i_track, or NULL if the + image has no such track. */ +static const track_info_t * +get_tocent_image(const _img_private_t *p_env, track_t i_track) +{ + if (i_track < p_env->gen.i_first_track + || i_track >= p_env->gen.i_first_track + p_env->gen.i_tracks) + return NULL; + return &p_env->tocent[i_track - p_env->gen.i_first_track]; +} + /** Return number of channels in track: 2 or 4; -2 if not implemented or -1 for error. Not meaningful if track is not an audio track. @@ -248,9 +259,10 @@ _get_track_msf_image(void *p_user_data, track_t i_track, msf_t *msf) int get_track_channels_image(const void *p_user_data, track_t i_track) { - const _img_private_t *p_env = p_user_data; - return ( p_env->tocent[i_track-p_env->gen.i_first_track].flags - & FOUR_CHANNEL_AUDIO ) ? 4 : 2; + const track_info_t *p_tocent = get_tocent_image(p_user_data, i_track); + + if (!p_tocent) return -1; + return ( p_tocent->flags & FOUR_CHANNEL_AUDIO ) ? 4 : 2; } /** Return 1 if copy is permitted on the track, 0 if not, or -1 for error. @@ -259,9 +271,11 @@ get_track_channels_image(const void *p_user_data, track_t i_track) track_flag_t get_track_copy_permit_image(void *p_user_data, track_t i_track) { - const _img_private_t *p_env = p_user_data; - return ( p_env->tocent[i_track-p_env->gen.i_first_track].flags - & COPY_PERMITTED ) ? CDIO_TRACK_FLAG_TRUE : CDIO_TRACK_FLAG_FALSE; + const track_info_t *p_tocent = get_tocent_image(p_user_data, i_track); + + if (!p_tocent) return CDIO_TRACK_FLAG_ERROR; + return ( p_tocent->flags & COPY_PERMITTED ) + ? CDIO_TRACK_FLAG_TRUE : CDIO_TRACK_FLAG_FALSE; } /** Return 1 if track has pre-emphasis, 0 if not, or -1 for error. @@ -272,9 +286,11 @@ get_track_copy_permit_image(void *p_user_data, track_t i_track) track_flag_t get_track_preemphasis_image(const void *p_user_data, track_t i_track) { - const _img_private_t *p_env = p_user_data; - return ( p_env->tocent[i_track-p_env->gen.i_first_track].flags - & PRE_EMPHASIS ) ? CDIO_TRACK_FLAG_TRUE : CDIO_TRACK_FLAG_FALSE; + const track_info_t *p_tocent = get_tocent_image(p_user_data, i_track); + + if (!p_tocent) return CDIO_TRACK_FLAG_ERROR; + return ( p_tocent->flags & PRE_EMPHASIS ) + ? CDIO_TRACK_FLAG_TRUE : CDIO_TRACK_FLAG_FALSE; } /** Return the starting LBA for the pregap for track number i_track. @@ -284,11 +300,12 @@ get_track_preemphasis_image(const void *p_user_data, track_t i_track) lba_t get_track_pregap_lba_image(const void *p_user_data, track_t i_track) { - const _img_private_t *p_env = p_user_data; + const track_info_t *p_tocent = get_tocent_image(p_user_data, i_track); lba_t pregap, start_lba; - pregap = p_env->tocent[i_track-p_env->gen.i_first_track].pregap; - start_lba = p_env->tocent[i_track-p_env->gen.i_first_track].start_lba; + if (!p_tocent) return CDIO_INVALID_LBA; + pregap = p_tocent->pregap; + start_lba = p_tocent->start_lba; /* avoid initializing pregap to CDIO_INVALID_LBA by letting calloc do the work. also, nero files have the pregap set equal @@ -311,8 +328,8 @@ get_track_pregap_lba_image(const void *p_user_data, track_t i_track) char * get_track_isrc_image(const void *p_user_data, track_t i_track) { - const _img_private_t *p_env = p_user_data; - char *isrc = p_env->tocent[i_track-p_env->gen.i_first_track].isrc; + const track_info_t *p_tocent = get_tocent_image(p_user_data, i_track); + char *isrc = p_tocent ? p_tocent->isrc : NULL; if (isrc && isrc[0]) { return strdup(isrc); From 6ac6f23fa87b934aee9ea89d56893dd21477a415 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 17:57:35 +0200 Subject: [PATCH 2/6] bincue: reject track numbers that are out of sequence 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 --- lib/driver/image/bincue.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/driver/image/bincue.c b/lib/driver/image/bincue.c index 79749d63..4a922cbd 100644 --- a/lib/driver/image/bincue.c +++ b/lib/driver/image/bincue.c @@ -289,6 +289,7 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name) unsigned int i_line=0; /* line number in file of psz_line. */ int i = -1; /* Position in tocent. Same as cd->gen.i_tracks - 1 */ + int i_first_track = 1; /* Number of the first track */ char *psz_keyword, *psz_field, *psz_cue_name_dup; cdio_log_level_t log_level = (NULL == cd) ? CDIO_LOG_INFO : CDIO_LOG_WARN; cdtext_field_t cdtext_key; @@ -488,14 +489,18 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name) "Track number out of range 1 to %d, got %s.", CDIO_CD_MAX_TRACKS, psz_field); goto err_exit; } - if(cd) { - if (-1 == i) { + /* Track numbers must follow each other, so the last one is + at most 99 too. */ + if (-1 == i) { + i_first_track = i_track; + if (cd) cd->gen.i_first_track = i_track; - } else if(cd->gen.i_first_track + i + 1 != i_track) { - cdio_log(log_level, - "Track number out of sequence. Expected %d, got %d", - cd->gen.i_first_track + i + 1, i_track); - } + } else if (i_first_track + i + 1 != i_track) { + cdio_log(log_level, + "%s line %d: track number out of sequence. " + "Expected %d, got %d", psz_cue_name, i_line, + i_first_track + i + 1, i_track); + goto err_exit; } } if (NULL != (psz_field = strtok_r(NULL, " \t\n\r", &saveptr))) { From 3d7064e79887c0e36e4f6d848f4ee02b150f2dc1 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 17:57:35 +0200 Subject: [PATCH 3/6] bincue, nrg: free a value given again instead of leaking it 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 --- lib/driver/image/bincue.c | 16 +++++++++++++--- lib/driver/image/nrg.c | 12 +++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/driver/image/bincue.c b/lib/driver/image/bincue.c index 4a922cbd..f76a6497 100644 --- a/lib/driver/image/bincue.c +++ b/lib/driver/image/bincue.c @@ -367,7 +367,10 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name) } } - if (cd) cd->psz_mcn = strdup (psz_field); + if (cd) { + free(cd->psz_mcn); + cd->psz_mcn = strdup (psz_field); + } if (NULL != (psz_field = strtok_r(NULL, " \t\n\r", &saveptr))) { goto format_error; } @@ -461,9 +464,13 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name) char *dirname = cdio_dirname(psz_cue_name); char *filename = cdio_abspath(dirname, psz_field); if (cd) { + /* The "source" argument and an earlier FILE are replaced */ + free(cd->gen.source_name); cd->gen.source_name = strdup(filename); - if (i >= 0) + if (i >= 0) { + free(cd->tocent[i].filename); cd->tocent[i].filename = strdup(filename); + } } free(filename); free(dirname); @@ -772,7 +779,10 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name) } else if (0 == strcmp("ISRC", psz_keyword)) { if (0 <= i) { if (NULL != (psz_field = strtok_r(NULL, " \t\n\r", &saveptr))) { - if (cd) cd->tocent[i].isrc = strdup (psz_field); + if (cd) { + free(cd->tocent[i].isrc); + cd->tocent[i].isrc = strdup (psz_field); + } } else { goto format_error; } diff --git a/lib/driver/image/nrg.c b/lib/driver/image/nrg.c index 950ae644..9863724f 100644 --- a/lib/driver/image/nrg.c +++ b/lib/driver/image/nrg.c @@ -507,9 +507,12 @@ parse_nrg (_img_private_t *p_env, const char *psz_nrg_name, disc_mode = _dao_common->unknown[1]; /* We include an extra 0 byte so these can be used as C strings.*/ + free(p_env->psz_mcn); p_env->psz_mcn = calloc(1, CDIO_MCN_SIZE+1); - if (p_env->psz_mcn == NULL) + if (p_env->psz_mcn == NULL) { + free(footer_buf); return false; + } memcpy(p_env->psz_mcn, &(_dao_common->psz_mcn), CDIO_MCN_SIZE); p_env->psz_mcn[CDIO_MCN_SIZE] = '\0'; @@ -619,7 +622,12 @@ parse_nrg (_img_private_t *p_env, const char *psz_nrg_name, } else { _dao_array_common = &_ientries->track_info[i].common; } + free(p_env->tocent[i].isrc); p_env->tocent[i].isrc = calloc(1, CDIO_ISRC_SIZE+1); + if (p_env->tocent[i].isrc == NULL) { + free(footer_buf); + return false; + } memcpy(p_env->tocent[i].isrc, _dao_array_common->psz_isrc, CDIO_ISRC_SIZE); p_env->tocent[i].isrc[CDIO_ISRC_SIZE] = '\0'; if (p_env->tocent[i].isrc[0]) { @@ -922,6 +930,8 @@ parse_nrg (_img_private_t *p_env, const char *psz_nrg_name, free(footer_buf); return false; } + /* A later CD TEXT chunk replaces an earlier one */ + cdtext_destroy(p_env->gen.cdtext); p_env->gen.cdtext = cdtext_init (); if(0 !=cdtext_data_init (p_env->gen.cdtext, wdata, len)) { From 65c5c1deffb12b5113b0236ab8ca69e8970c829c Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 17:57:46 +0200 Subject: [PATCH 4/6] cdrdao: free a value given again instead of leaking it 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 --- lib/driver/image/cdrdao.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/driver/image/cdrdao.c b/lib/driver/image/cdrdao.c index ad830746..6a7637f4 100644 --- a/lib/driver/image/cdrdao.c +++ b/lib/driver/image/cdrdao.c @@ -304,6 +304,19 @@ get_disc_last_lsn_cdrdao (void *p_user_data) psz_cue_name, i_line, psz_keyword) +/* Free the file a track read so far, when FILE or DATAFILE is given + again for the same track */ +static void +free_track_file(track_info_t *p_tocent) +{ + free(p_tocent->filename); + p_tocent->filename = NULL; + if (p_tocent->data_source) { + cdio_stdio_destroy(p_tocent->data_source); + p_tocent->data_source = NULL; + } +} + static bool parse_tocfile (_img_private_t *cd, const char *psz_cue_name) { @@ -380,7 +393,10 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name) goto err_exit; } } - if (NULL != cd) cd->psz_mcn = strdup (psz_field); + if (NULL != cd) { + free(cd->psz_mcn); + cd->psz_mcn = strdup (psz_field); + } } } else { cdio_log(log_level, @@ -709,8 +725,10 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name) if (i_track < 0) goto not_in_global_section; if (NULL != (psz_field = strtok_r(NULL, "\"\t\n\r", &saveptr))) { - if (NULL != cd) + if (NULL != cd) { + free(cd->tocent[i_track].isrc); cd->tocent[i_track].isrc = strdup(psz_field); + } } else { goto format_error; } @@ -748,6 +766,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name) char *psz_filename = cdio_abspath(psz_dirname, psz_field); free(psz_dirname); if (cd) { + free_track_file(&cd->tocent[i_track]); cd->tocent[i_track].filename = strdup (psz_filename); /* To do: do something about reusing existing files. */ if (!(cd->tocent[i_track].data_source = cdio_stdio_new (psz_filename))) { @@ -827,6 +846,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name) char *psz_dirname = cdio_dirname(psz_cue_name); char *psz_filename = cdio_abspath(psz_dirname, psz_field); if (cd) { + free_track_file(&cd->tocent[i_track]); cd->tocent[i_track].filename = strdup(psz_filename); /* To do: do something about reusing existing files. */ if (!(cd->tocent[i_track].data_source = cdio_stdio_new (psz_filename))) { From 12b18b05cf97dc1cbf99f278aa32691112319ba2 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 17:57:46 +0200 Subject: [PATCH 5/6] cdrdao: free the tracks read so far when a TOC file fails to parse 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 --- lib/driver/image/cdrdao.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/driver/image/cdrdao.c b/lib/driver/image/cdrdao.c index 6a7637f4..7eff01f8 100644 --- a/lib/driver/image/cdrdao.c +++ b/lib/driver/image/cdrdao.c @@ -1094,6 +1094,9 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name) psz_cue_name, i_line, psz_keyword); err_exit: + /* Let the caller free the tracks read so far */ + if (NULL != cd) + cd->gen.i_tracks = i_track+1; fclose (fp); return false; } From 609fd57ece6e2eaae1b83f561d0ae793b279792f Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 17:58:31 +0200 Subject: [PATCH 6/6] test: track numbers out of range or sequence, and repeated keywords 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 --- test/driver/bincue.c | 158 +++++++++++++++++++++++++++++++++++++++++++ test/driver/cdrdao.c | 82 ++++++++++++++++++++++ 2 files changed, 240 insertions(+) diff --git a/test/driver/bincue.c b/test/driver/bincue.c index 46a80c62..a6535597 100644 --- a/test/driver/bincue.c +++ b/test/driver/bincue.c @@ -312,6 +312,161 @@ check_read_past_end(void) return ret; } +/* Write a cue sheet whose FILE is a 4-sector BIN file of zeros, followed + by psz_body, and open it. Both files are in the current directory and + are removed again; the BIN file only once p_cdio is destroyed, which + remove_bin_cue() does. */ +static const char *bin_cue_bin = "bincue-tracks.bin"; + +static CdIo_t * +open_bin_cue(const char *psz_body) +{ + const char *cue_name = "bincue-tracks.cue"; + FILE *cue, *bin; + CdIo_t *p_cdio; + long i; + + bin = fopen(bin_cue_bin, "wb"); + if (!bin) { + printf("Can't create %s\n", bin_cue_bin); + return NULL; + } + for (i = 0; i < 4 * CDIO_CD_FRAMESIZE_RAW; i++) + fputc(0, bin); + fclose(bin); + cue = fopen(cue_name, "w"); + if (!cue) { + printf("Can't create %s\n", cue_name); + return NULL; + } + fprintf(cue, "FILE \"%s\" BINARY\n%s", bin_cue_bin, psz_body); + fclose(cue); + + p_cdio = cdio_open_bincue(cue_name); + remove(cue_name); + return p_cdio; +} + +static void +remove_bin_cue(CdIo_t *p_cdio) +{ + if (p_cdio) + cdio_destroy(p_cdio); + remove(bin_cue_bin); +} + +/* The track getters must reject a track number the image doesn't have, + also below the first track: they used to index the table of tracks + with it */ +static int +check_track_range(void) +{ + static const track_t bad[] = { 1, 98, 100 }; + CdIo_t *p_cdio = open_bin_cue(" TRACK 99 AUDIO\n INDEX 01 00:00:00\n"); + unsigned int i; + int ret = 0; + + if (!p_cdio) { + printf("Can't open a cue sheet whose only track is 99\n"); + remove_bin_cue(NULL); + return 1; + } + if (CDIO_TRACK_FLAG_ERROR == cdio_get_track_copy_permit(p_cdio, 99) + || -1 == cdio_get_track_channels(p_cdio, 99)) { + printf("Incorrect: track 99 is rejected.\n"); + ret = 1; + } + for (i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) { + char *isrc = cdio_get_track_isrc(p_cdio, bad[i]); + + if (isrc + || -1 != cdio_get_track_channels(p_cdio, bad[i]) + || CDIO_TRACK_FLAG_ERROR != cdio_get_track_copy_permit(p_cdio, bad[i]) + || CDIO_TRACK_FLAG_ERROR != cdio_get_track_preemphasis(p_cdio, bad[i]) + || CDIO_INVALID_LBA != cdio_get_track_pregap_lba(p_cdio, bad[i])) { + printf("Incorrect: track %u of a disc with only track 99 accepted.\n", + (unsigned int) bad[i]); + ret = 1; + } + free(isrc); + } + remove_bin_cue(p_cdio); + return ret; +} + +/* Track numbers must follow each other. A first track of 99 followed by + 2 and 3 used to give a disc whose last track is 101 */ +static int +check_track_sequence(void) +{ + static const char *const bad[] = { + " TRACK 99 AUDIO\n INDEX 01 00:00:00\n" + " TRACK 02 AUDIO\n INDEX 01 00:00:01\n" + " TRACK 03 AUDIO\n INDEX 01 00:00:02\n", + " TRACK 01 AUDIO\n INDEX 01 00:00:00\n" + " TRACK 03 AUDIO\n INDEX 01 00:00:01\n", + " TRACK 02 AUDIO\n INDEX 01 00:00:00\n" + " TRACK 01 AUDIO\n INDEX 01 00:00:01\n", + }; + unsigned int i; + int ret = 0; + CdIo_t *p_cdio = open_bin_cue(" TRACK 98 AUDIO\n INDEX 01 00:00:00\n" + " TRACK 99 AUDIO\n INDEX 01 00:00:01\n"); + + if (!p_cdio || 99 != cdio_get_last_track_num(p_cdio)) { + printf("Incorrect: tracks 98 and 99 don't open.\n"); + ret = 1; + } + remove_bin_cue(p_cdio); + for (i = 0; i < sizeof(bad) / sizeof(bad[0]); i++) { + p_cdio = open_bin_cue(bad[i]); + if (p_cdio) { + printf("Incorrect: tracks out of sequence opened (case %u).\n", i); + ret = 1; + } + remove_bin_cue(p_cdio); + } + return ret; +} + +/* A keyword given twice replaces the first value. The first value + used to be leaked, which only a memory checker sees */ +static int +check_repeated_keywords(void) +{ + CdIo_t *p_cdio = open_bin_cue("CATALOG 0000000000001\n" + "CATALOG 0000000000002\n" + "FILE \"bincue-tracks.bin\" BINARY\n" + " TRACK 01 AUDIO\n" + " ISRC USAAA0000001\n" + " ISRC USAAA0000002\n" + " INDEX 01 00:00:00\n"); + char *psz; + int ret = 0; + + if (!p_cdio) { + printf("Incorrect: repeated CATALOG, FILE and ISRC don't open.\n"); + remove_bin_cue(NULL); + return 1; + } + psz = cdio_get_track_isrc(p_cdio, 1); + if (!psz || strcmp(psz, "USAAA0000002")) { + printf("Incorrect: ISRC is %s, not the last one given.\n", + psz ? psz : "(none)"); + ret = 1; + } + free(psz); + psz = cdio_get_mcn(p_cdio); + if (!psz || strcmp(psz, "0000000000002")) { + printf("Incorrect: CATALOG is %s, not the last one given.\n", + psz ? psz : "(none)"); + ret = 1; + } + free(psz); + remove_bin_cue(p_cdio); + return ret; +} + static int check_mode2_seek(const char *cue_name, const char *mode) { @@ -375,6 +530,9 @@ main(int argc, const char *argv[]) ret = 1; if (check_read_past_end()) ret = 1; + if (check_track_range() || check_track_sequence() + || check_repeated_keywords()) + ret = 1; if (check_mode2_seek("mode2-2048.cue", "MODE2/2048") || check_mode2_seek("mode2-2324.cue", "MODE2/2324")) ret = 1; diff --git a/test/driver/cdrdao.c b/test/driver/cdrdao.c index 709e8757..51bd538d 100644 --- a/test/driver/cdrdao.c +++ b/test/driver/cdrdao.c @@ -757,6 +757,86 @@ check_read_past_end(void) return ret; } +/* Write psz_body to a TOC file next to a 4-sector data file and open + it. Both files are removed again. */ +static CdIo_t * +open_toc(const char *psz_body) +{ + const char *toc_name = "cdrdao-keywords.toc"; + FILE *toc = fopen(toc_name, "w"); + CdIo_t *p_cdio; + + if (!toc) { + fprintf(stderr, "Unable to create %s\n", toc_name); + return NULL; + } + fprintf(toc, "%s", psz_body); + fclose(toc); + p_cdio = cdio_open_cdrdao(toc_name); + remove(toc_name); + return p_cdio; +} + +/* A keyword given twice replaces the first value, and a TOC file that + fails after its first track is rejected. The first value, and the + tracks read before the error, used to be leaked, which only a memory + checker sees */ +static int +check_repeated_keywords(void) +{ + const char *bin_name = "cdrdao-keywords.bin"; + CdIo_t *p_cdio; + char *psz; + int ret = 0; + + if (write_zeros(bin_name, 4 * CDIO_CD_FRAMESIZE_RAW)) + return 1; + p_cdio = open_toc("CD_DA\n" + "CATALOG \"0000000000001\"\n" + "CATALOG \"0000000000002\"\n" + "TRACK AUDIO\n" + "ISRC \"USAAA0000001\"\n" + "ISRC \"USAAA0000002\"\n" + "FILE \"cdrdao-keywords.bin\" 0\n" + "DATAFILE \"cdrdao-keywords.bin\"\n"); + if (!p_cdio) { + fprintf(stderr, + "Incorrect: repeated CATALOG, FILE and ISRC don't open.\n"); + remove(bin_name); + return 1; + } + psz = cdio_get_track_isrc(p_cdio, 1); + if (!psz || strcmp(psz, "USAAA0000002")) { + fprintf(stderr, "Incorrect: ISRC is %s, not the last one given.\n", + psz ? psz : "(none)"); + ret = 1; + } + free(psz); + psz = cdio_get_mcn(p_cdio); + if (!psz || strcmp(psz, "0000000000002")) { + fprintf(stderr, "Incorrect: CATALOG is %s, not the last one given.\n", + psz ? psz : "(none)"); + ret = 1; + } + free(psz); + cdio_destroy(p_cdio); + + /* The second track is longer than the file */ + p_cdio = open_toc("CD_DA\n" + "TRACK AUDIO\n" + "ISRC \"USAAA0000001\"\n" + "FILE \"cdrdao-keywords.bin\" 0\n" + "TRACK AUDIO\n" + "FILE \"cdrdao-keywords.bin\" 0 50:00:00\n"); + if (p_cdio) { + fprintf(stderr, "Incorrect: a track longer than its file opened.\n"); + cdio_destroy(p_cdio); + ret = 1; + } + remove(bin_name); + return ret; +} + int main(int argc, const char *argv[]) { @@ -817,6 +897,8 @@ main(int argc, const char *argv[]) ret = 1; if (check_bad_datafile_length() || check_read_past_end()) ret = 1; + if (check_repeated_keywords()) + ret = 1; #ifdef HAVE_CHDIR if (0 == chdir(DATA_DIR)) #endif