From 8e5233667ce673632e21298f07978a18641c923c Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:04 +0200 Subject: [PATCH 1/7] iso9660: give the stat found by LSN its own symlink find_lsn_recurse() copied the iso9660_stat_t of the entry it found, pointer to the Rock Ridge symlink included, then freed the directory list and with it the symlink. The stat it returned held a freed pointer: - iso9660_ifs_find_lsn() and iso9660_fs_find_lsn() returned it, and iso9660_stat_free() freed the symlink a second time. Any image whose file at that LSN is a symbolic link does it. - A Rock Ridge CL entry looks up the directory it points to with the same function while the directory holding the CL entry is read. The entry took the freed symlink, so reading a directory whose CL entry points to a symbolic link read freed memory, and freeing the list freed it again. Hand the symlink over to the returned stat instead. The CL entry also lost its own symlink when the target's stat was copied over it: free it first. Co-Authored-By: Claude Opus 5.5 --- lib/iso9660/iso9660_fs.c | 2 ++ lib/iso9660/rock.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index d6f457c6..d9e3145b 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -1802,6 +1802,8 @@ find_lsn_recurse (void *p_image, iso9660_readdir_t iso9660_readdir, return NULL; } memcpy(ret_stat, statbuf, len2); + /* ret_stat now owns the symlink: don't free it with the list. */ + statbuf->rr.psz_symlink = NULL; iso9660_filelist_free (entlist); iso9660_dirlist_free(dirlist); return ret_stat; diff --git a/lib/iso9660/rock.c b/lib/iso9660/rock.c index 6b265168..59c4bff7 100644 --- a/lib/iso9660/rock.c +++ b/lib/iso9660/rock.c @@ -397,6 +397,8 @@ get_rock_ridge_filename(iso9660_dir_t * p_iso9660_dir, cdio_warn("Could not get Rock Ridge deep directory child"); break; } + /* p_stat takes the target's symlink below: free its own. */ + free(p_stat->rr.psz_symlink); memcpy(p_stat, target, sizeof(iso9660_stat_t)); /* Prevent the symlink from being freed on the duplicated struct */ target->rr.psz_symlink = NULL; From d026861c9c5be2a0f0c1cf78419fb5309c2d4025 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:04 +0200 Subject: [PATCH 2/7] rock: allocate the symlink buffer whenever it's missing realloc_symlink() allocated a new buffer only while the symlink was empty, and otherwise copied the symlink from the existing one. An SL entry that is continued counts the separator before the next record stores it, so the length can be 1 with no buffer at all: an SL entry with the continue flag whose only component has a flag that isn't implemented made realloc_symlink() copy a byte from NULL. And with an empty symlink and a buffer, it allocated another buffer and leaked the first one. Decide on the buffer itself, copy no more than it holds, and keep room for the final NUL. Co-Authored-By: Claude Opus 5.5 --- lib/iso9660/rock.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/iso9660/rock.c b/lib/iso9660/rock.c index 59c4bff7..3952033c 100644 --- a/lib/iso9660/rock.c +++ b/lib/iso9660/rock.c @@ -62,25 +62,30 @@ _iso9660_dd_find_lsn(void* p_image, lsn_t i_lsn); static bool realloc_symlink(/*in/out*/ iso9660_stat_t *p_stat, uint8_t i_grow) { - if (!p_stat->rr.i_symlink) { - const uint16_t i_max = 2*i_grow+1; - p_stat->rr.psz_symlink = (char *) calloc(1, i_max); - p_stat->rr.i_symlink_max = i_max; - return (NULL != p_stat->rr.psz_symlink); - } else { - unsigned int i_needed = p_stat->rr.i_symlink + i_grow * 2; // Allocate enough space for growth and additional buffer - if ( i_needed <= p_stat->rr.i_symlink_max) - return true; - else { - char * psz_newsymlink = (char *) calloc(1, 2*i_needed); - if (!psz_newsymlink) return false; - p_stat->rr.i_symlink_max = 2*i_needed; - memcpy(psz_newsymlink, p_stat->rr.psz_symlink, p_stat->rr.i_symlink); - free(p_stat->rr.psz_symlink); - p_stat->rr.psz_symlink = psz_newsymlink; - return true; - } + /* Allocate enough space for growth, an additional buffer and the + final NUL. */ + const unsigned int i_needed = p_stat->rr.i_symlink + i_grow * 2 + 1; + char *psz_newsymlink; + + if (p_stat->rr.psz_symlink != NULL + && i_needed <= (unsigned int) p_stat->rr.i_symlink_max) + return true; + + psz_newsymlink = (char *) calloc(1, 2*i_needed); + if (!psz_newsymlink) return false; + /* The length can be ahead of the buffer: an SL record that is + continued counts the separator before it allocates it, and the + buffer can be missing altogether when no component was stored. */ + if (p_stat->rr.psz_symlink != NULL) { + const int i_copy = p_stat->rr.i_symlink < p_stat->rr.i_symlink_max + ? p_stat->rr.i_symlink : p_stat->rr.i_symlink_max; + if (i_copy > 0) + memcpy(psz_newsymlink, p_stat->rr.psz_symlink, i_copy); + free(p_stat->rr.psz_symlink); } + p_stat->rr.psz_symlink = psz_newsymlink; + p_stat->rr.i_symlink_max = 2*i_needed; + return true; } /* These functions are designed to read the system areas of a directory record From 51b44e8ace93ed523cd6554474d60ffda2679fe1 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:04 +0200 Subject: [PATCH 3/7] iso9660: skip a directory that can't be read when looking for an LSN find_lsn_recurse() asserted that every directory can be read, so iso9660_ifs_find_lsn() and iso9660_fs_find_lsn() aborted the program on an image with a directory of length 0, an extent past the end, a path deeper than MAX_ISO9660_PATH_DEPTH or any other directory that iso9660_ifs_readdir() rejects. Because a Rock Ridge CL entry looks up its target in the same way, reading a directory with a CL entry was enough. Warn and go on with the other directories. Co-Authored-By: Claude Opus 5.5 --- lib/iso9660/iso9660_fs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index d9e3145b..f6a6551e 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -1772,10 +1772,16 @@ find_lsn_recurse (void *p_image, iso9660_readdir_t iso9660_readdir, CdioList_t *visited) { CdioISO9660FileList_t *entlist = iso9660_readdir (p_image, psz_path); - CdioISO9660DirList_t *dirlist = iso9660_filelist_new(); + CdioISO9660DirList_t *dirlist; CdioListNode_t *entnode; - cdio_assert (entlist != NULL); + /* A directory that can't be read doesn't hold the LSN: go on with + the others. */ + if (entlist == NULL) { + cdio_warn("Can't read directory %s", psz_path); + return NULL; + } + dirlist = iso9660_filelist_new(); /* iterate over each entry in the directory */ From 29c510b0e2838de0700c95e7d85bd424689b785c Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:04 +0200 Subject: [PATCH 4/7] iso9660: don't read a short directory record past its block The loops over directory records read the fixed part of each record, 33 bytes, even when _iso9660_dir_to_statbuf() rejects it for a length below that: file_flags decides whether a multi-extent file goes on. iso9660_check_dir_block_end() only checked that the record's own length stays within the block, so a record with a length from 1 to 32 in the last bytes of a directory's last block made them read up to 24 bytes past the directory buffer. Treat a record as long as its fixed part at least when checking for the end of the block. A short record elsewhere is still read and rejected as before. Co-Authored-By: Claude Opus 5.5 --- lib/iso9660/iso9660_fs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index f6a6551e..779ffa4c 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -752,6 +752,8 @@ iso9660_iso_seek_read (const iso9660_t *p_iso, void *ptr, lsn_t start, static bool iso9660_check_dir_block_end(iso9660_dir_t *p_iso9660_dir, unsigned *offset) { + unsigned int i_len; + if (!iso9660_get_dir_len(p_iso9660_dir)) { /* @@ -766,8 +768,14 @@ iso9660_check_dir_block_end(iso9660_dir_t *p_iso9660_dir, unsigned *offset) return true; } - if ((*offset + iso9660_get_dir_len(p_iso9660_dir) - 1) / ISO_BLOCKSIZE - != *offset / ISO_BLOCKSIZE) + /* A record shorter than its fixed part is malformed, and callers + still read the fixed part: check that it fits in the block too, + or reading it at the end of the last block goes past the buffer. */ + i_len = iso9660_get_dir_len(p_iso9660_dir); + if (i_len < sizeof(iso9660_dir_t)) + i_len = sizeof(iso9660_dir_t); + + if ((*offset + i_len - 1) / ISO_BLOCKSIZE != *offset / ISO_BLOCKSIZE) { /* Directory record spans over block limit. From 83d971dae1917e602e657e23dbb3a6534f49b0dd Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:05 +0200 Subject: [PATCH 5/7] iso9660: look for the PVD identifier only within the frame iso9660_ifs_fuzzy_read_superblock() looked for "CD001" with strstr() from each 'C' in a frame. A frame of 2352 bytes fills the buffer, so when it held no NUL, as on an image of any other data, strstr() read past the buffer on the stack. Compare the 5 bytes at each 'C' that has room for them. Co-Authored-By: Claude Opus 5.5 --- lib/iso9660/iso9660_fs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index 779ffa4c..2ddd18e5 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -591,11 +591,18 @@ iso9660_ifs_fuzzy_read_superblock (iso9660_t *p_iso, return false; } + /* The frame isn't NUL-terminated when the whole of it is read, + so look for the identifier only within the frame. */ q = memchr(frame, 'C', p_iso->i_framesize); for ( p=q; p && p < frame + p_iso->i_framesize ; p=q+1 ) { q = memchr(p, 'C', p_iso->i_framesize - (p - frame)); - if ( !q || (pvd = strstr(q, ISO_STANDARD_ID)) ) + if (!q) break; + if (q + strlen(ISO_STANDARD_ID) <= frame + p_iso->i_framesize + && 0 == memcmp(q, ISO_STANDARD_ID, strlen(ISO_STANDARD_ID))) { + pvd = q; + break; + } } if (pvd) { From 984bab899e331b01e82c505176891fdd0ec89b09 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:05 +0200 Subject: [PATCH 6/7] iso9660: copy the root's symlink only when it has one _fs_stat_traverse() and _fs_iso_stat_traverse() copied the root's symlink buffer into the stat they return for the root even when it had none, passing NULL to memcpy() with a length of 0, which is undefined, and asserting on calloc() of 0 bytes, which may return NULL. Co-Authored-By: Claude Opus 5.5 --- lib/iso9660/iso9660_fs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index 2ddd18e5..38490051 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -1189,10 +1189,12 @@ _fs_stat_traverse (const CdIo_t *p_cdio, const iso9660_stat_t *_root, p_stat = calloc(1, len); cdio_assert (p_stat != NULL); memcpy(p_stat, _root, len); - p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max); - cdio_assert (p_stat->rr.psz_symlink != NULL); - memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, - p_stat->rr.i_symlink_max); + if (_root->rr.psz_symlink != NULL) { + p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max); + cdio_assert (p_stat->rr.psz_symlink != NULL); + memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, + p_stat->rr.i_symlink_max); + } return p_stat; } @@ -1304,10 +1306,12 @@ _fs_iso_stat_traverse (iso9660_t *p_iso, const iso9660_stat_t *_root, p_stat = calloc(1, len); cdio_assert (p_stat != NULL); memcpy(p_stat, _root, len); - p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max); - cdio_assert (p_stat->rr.psz_symlink != NULL); - memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, - p_stat->rr.i_symlink_max); + if (_root->rr.psz_symlink != NULL) { + p_stat->rr.psz_symlink = calloc(1, p_stat->rr.i_symlink_max); + cdio_assert (p_stat->rr.psz_symlink != NULL); + memcpy(p_stat->rr.psz_symlink, _root->rr.psz_symlink, + p_stat->rr.i_symlink_max); + } return p_stat; } From 4253bf3cfc350d632abf80c354ef063a34909e92 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Tue, 17 Nov 2026 08:19:05 +0200 Subject: [PATCH 7/7] test: read ISO 9660 images with bad Rock Ridge and directory records testisorr builds small images to check that: - iso9660_ifs_find_lsn() returns a stat whose symlink can be read and freed; - a Rock Ridge CL entry and the symbolic link it points to both read the link; - an SL entry whose only component has an unknown flag can be read; - looking for an LSN goes past a directory of length 0, both for an LSN that isn't on the image and for one in a later file; - short records at the end of a directory's block, and the fuzzy search on frames full of 'C', can be read. The last two only show a difference under a memory checker such as valgrind. Co-Authored-By: Claude Opus 5.5 --- test/testisorr.c | 349 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 349 insertions(+) diff --git a/test/testisorr.c b/test/testisorr.c index 6d16a40e..ddeed9ff 100644 --- a/test/testisorr.c +++ b/test/testisorr.c @@ -337,6 +337,325 @@ check_malformed_record(void) return result; } +/* Opens a new temporary file for writing. psz_tmp receives its name. */ +static FILE * +open_temp(char *psz_tmp, const char *psz_template) +{ +#ifdef HAVE_MKSTEMP + int fd; + FILE *fp; + + strcpy(psz_tmp, psz_template); + fd = mkstemp(psz_tmp); + if (fd < 0) + return NULL; + fp = fdopen(fd, "wb"); + if (!fp) + close(fd); + return fp; +#else + (void) psz_template; + if (!tmpnam(psz_tmp)) + return NULL; + return fopen(psz_tmp, "wb"); +#endif +} + +#define TEST_IMAGE_BLOCKS 40 +#define TEST_ROOT_LSN 20 + +/* Writes a 40-block image whose root directory, at block 20, is dir. */ +static int +write_test_image(char *psz_tmp, const char *psz_template, + const uint8_t dir[ISO_BLOCKSIZE]) +{ + uint8_t pvd[ISO_BLOCKSIZE] = {0}; + FILE *fp = open_temp(psz_tmp, psz_template); + + if (!fp) + return 1; + + pvd[0] = 1; + memcpy(&pvd[1], "CD001", 5); + pvd[6] = 1; + put_733(&pvd[80], TEST_IMAGE_BLOCKS); + pvd[128] = 0; + pvd[129] = 8; + pvd[156] = 34; + put_733(&pvd[158], TEST_ROOT_LSN); + put_733(&pvd[166], ISO_BLOCKSIZE); + pvd[181] = ISO_DIRECTORY; + pvd[188] = 1; + + if (fseek(fp, TEST_IMAGE_BLOCKS * ISO_BLOCKSIZE - 1, SEEK_SET) != 0 + || fputc(0, fp) == EOF + || fseek(fp, 16 * ISO_BLOCKSIZE, SEEK_SET) != 0 + || fwrite(pvd, 1, sizeof(pvd), fp) != sizeof(pvd)) + goto fail; + memset(pvd, 0, sizeof(pvd)); + pvd[0] = 255; + memcpy(&pvd[1], "CD001", 5); + pvd[6] = 1; + if (fwrite(pvd, 1, sizeof(pvd), fp) != sizeof(pvd) + || fseek(fp, TEST_ROOT_LSN * ISO_BLOCKSIZE, SEEK_SET) != 0 + || fwrite(dir, 1, ISO_BLOCKSIZE, fp) != ISO_BLOCKSIZE) + goto fail; + return fclose(fp) != 0; + +fail: + fclose(fp); + return 1; +} + +/* Adds a directory record with an optional System Use area. */ +static unsigned +add_su_record(uint8_t *dir, unsigned offset, uint32_t extent, uint32_t size, + uint8_t flags, const char *name, unsigned name_len, + const uint8_t *su, unsigned su_len) +{ + uint8_t *record = dir + offset; + unsigned length = 33 + name_len; + + if (length % 2) + length++; + memset(record, 0, length + su_len); + record[0] = length + su_len; + put_733(record + 2, extent); + put_733(record + 10, size); + record[25] = flags; + record[28] = 1; + record[32] = name_len; + memcpy(record + 33, name, name_len); + if (su_len) + memcpy(record + length, su, su_len); + return offset + length + su_len; +} + +/* Adds the "." and ".." records of the root directory. */ +static unsigned +add_root_dots(uint8_t *dir) +{ + unsigned offset = add_su_record(dir, 0, TEST_ROOT_LSN, ISO_BLOCKSIZE, + ISO_DIRECTORY, "\0", 1, NULL, 0); + return add_su_record(dir, offset, TEST_ROOT_LSN, ISO_BLOCKSIZE, + ISO_DIRECTORY, "\1", 1, NULL, 0); +} + +/* A Rock Ridge SL entry for the one-component link "x". */ +static const uint8_t sl_x[] = { 'S', 'L', 8, 1, 0, 0, 1, 'x' }; + +/* The stat that iso9660_ifs_find_lsn() returns owns its symlink. */ +static int +check_find_lsn_symlink(void) +{ + uint8_t dir[ISO_BLOCKSIZE] = {0}; + char psz_tmp[64 + L_tmpnam]; + iso9660_t *p_iso = NULL; + iso9660_stat_t *p_stat = NULL; + int ret = 1; + + add_su_record(dir, add_root_dots(dir), 31, 0, 0, "L;1", 3, + sl_x, sizeof(sl_x)); + if (write_test_image(psz_tmp, "libcdio-rr-lsn-XXXXXX", dir) != 0) + goto out; + + p_iso = iso9660_open_ext(psz_tmp, ISO_EXTENSION_ALL); + if (!p_iso) + goto out; + p_stat = iso9660_ifs_find_lsn(p_iso, 31); + if (p_stat && p_stat->rr.psz_symlink + && 0 == strcmp(p_stat->rr.psz_symlink, "x")) + ret = 0; + +out: + if (p_stat) + iso9660_stat_free(p_stat); + if (p_iso) + iso9660_close(p_iso); + remove(psz_tmp); + return ret; +} + +/* A Rock Ridge CL entry takes the symlink of the entry it points to. */ +static int +check_child_link_symlink(void) +{ + uint8_t dir[ISO_BLOCKSIZE] = {0}; + uint8_t cl[12] = { 'C', 'L', 12, 1 }; + char psz_tmp[64 + L_tmpnam]; + iso9660_t *p_iso = NULL; + CdioISO9660FileList_t *entries = NULL; + CdioListNode_t *node; + unsigned offset; + int links = 0; + int ret = 1; + + put_733(cl + 4, 31); + offset = add_su_record(dir, add_root_dots(dir), 30, 0, 0, "C;1", 3, + cl, sizeof(cl)); + add_su_record(dir, offset, 31, 0, 0, "L;1", 3, sl_x, sizeof(sl_x)); + if (write_test_image(psz_tmp, "libcdio-rr-cl-XXXXXX", dir) != 0) + goto out; + + p_iso = iso9660_open_ext(psz_tmp, ISO_EXTENSION_ALL); + if (!p_iso) + goto out; + entries = iso9660_ifs_readdir(p_iso, "/"); + if (!entries) + goto out; + _CDIO_LIST_FOREACH (node, entries) { + iso9660_stat_t *p_stat = _cdio_list_node_data(node); + if (p_stat->rr.psz_symlink && 0 == strcmp(p_stat->rr.psz_symlink, "x")) + links++; + } + /* Both the link and the entry that points to it. */ + if (links == 2) + ret = 0; + +out: + if (entries) + iso9660_filelist_free(entries); + if (p_iso) + iso9660_close(p_iso); + remove(psz_tmp); + return ret; +} + +/* An SL entry whose only component has an unknown flag stores nothing. */ +static int +check_unknown_symlink_component(void) +{ + static const uint8_t sl[] = { 'S', 'L', 7, 1, 1, 0x10, 0 }; + uint8_t dir[ISO_BLOCKSIZE] = {0}; + char psz_tmp[64 + L_tmpnam]; + iso9660_t *p_iso = NULL; + CdioISO9660FileList_t *entries = NULL; + int ret = 1; + + add_su_record(dir, add_root_dots(dir), 30, 0, 0, "A;1", 3, sl, sizeof(sl)); + if (write_test_image(psz_tmp, "libcdio-rr-sl-XXXXXX", dir) != 0) + goto out; + + p_iso = iso9660_open_ext(psz_tmp, ISO_EXTENSION_ALL); + if (!p_iso) + goto out; + entries = iso9660_ifs_readdir(p_iso, "/"); + if (entries) + ret = 0; + +out: + if (entries) + iso9660_filelist_free(entries); + if (p_iso) + iso9660_close(p_iso); + remove(psz_tmp); + return ret; +} + +/* Looking for an LSN goes past a directory that can't be read. */ +static int +check_find_lsn_unreadable_directory(void) +{ + uint8_t dir[ISO_BLOCKSIZE] = {0}; + char psz_tmp[64 + L_tmpnam]; + iso9660_t *p_iso = NULL; + iso9660_stat_t *p_stat = NULL; + unsigned offset; + int ret = 1; + + /* A directory of length 0, then a file after it. */ + offset = add_su_record(dir, add_root_dots(dir), 19, 0, ISO_DIRECTORY, + "D", 1, NULL, 0); + add_su_record(dir, offset, 32, 0, 0, "F;1", 3, NULL, 0); + if (write_test_image(psz_tmp, "libcdio-rr-dir-XXXXXX", dir) != 0) + goto out; + + p_iso = iso9660_open_ext(psz_tmp, ISO_EXTENSION_ALL); + if (!p_iso) + goto out; + /* Not on the image: every directory is searched. */ + p_stat = iso9660_ifs_find_lsn(p_iso, 35); + if (p_stat) + goto out; + p_stat = iso9660_ifs_find_lsn(p_iso, 32); + if (p_stat) + ret = 0; + +out: + if (p_stat) + iso9660_stat_free(p_stat); + if (p_iso) + iso9660_close(p_iso); + remove(psz_tmp); + return ret; +} + +/* Records shorter than their fixed part at the end of the last block of + a directory aren't read past the block. Only a memory checker sees + the difference. */ +static int +check_short_record_at_block_end(void) +{ + uint8_t dir[ISO_BLOCKSIZE] = {0}; + char psz_tmp[64 + L_tmpnam]; + iso9660_t *p_iso = NULL; + CdioISO9660FileList_t *entries = NULL; + unsigned offset = add_root_dots(dir); + int ret = 1; + + memset(dir + offset, 1, ISO_BLOCKSIZE - offset); + if (write_test_image(psz_tmp, "libcdio-rr-short-XXXXXX", dir) != 0) + goto out; + + p_iso = iso9660_open_ext(psz_tmp, ISO_EXTENSION_ALL); + if (!p_iso) + goto out; + entries = iso9660_ifs_readdir(p_iso, "/"); + ret = 0; + +out: + if (entries) + iso9660_filelist_free(entries); + if (p_iso) + iso9660_close(p_iso); + remove(psz_tmp); + return ret; +} + +/* The fuzzy search for a PVD doesn't read past a frame that holds no + NUL. Only a memory checker sees the difference. */ +static int +check_fuzzy_frame_without_nul(void) +{ + uint8_t frame[CDIO_CD_FRAMESIZE_RAW]; + char psz_tmp[64 + L_tmpnam]; + iso9660_t *p_iso = NULL; + FILE *fp = open_temp(psz_tmp, "libcdio-rr-fuzzy-XXXXXX"); + int i; + int ret = 1; + + if (!fp) + return 1; + memset(frame, 'C', sizeof(frame)); + for (i = 0; i < 24; i++) + if (fwrite(frame, 1, sizeof(frame), fp) != sizeof(frame)) { + fclose(fp); + goto out; + } + if (fclose(fp) != 0) + goto out; + + p_iso = iso9660_open_fuzzy_ext(psz_tmp, ISO_EXTENSION_ALL, 20); + if (!p_iso) + ret = 0; + +out: + if (p_iso) + iso9660_close(p_iso); + remove(psz_tmp); + return ret; +} + int main(int argc, const char *argv[]) { @@ -401,5 +720,35 @@ main(int argc, const char *argv[]) return 6; } + if (check_find_lsn_symlink() != 0) { + fprintf(stderr, "Symlink of a stat found by LSN is wrong\n"); + return 7; + } + + if (check_child_link_symlink() != 0) { + fprintf(stderr, "Symlink of a Rock Ridge child link is wrong\n"); + return 8; + } + + if (check_unknown_symlink_component() != 0) { + fprintf(stderr, "Unknown symlink component was not handled\n"); + return 9; + } + + if (check_find_lsn_unreadable_directory() != 0) { + fprintf(stderr, "Unreadable directory stopped the LSN search\n"); + return 10; + } + + if (check_short_record_at_block_end() != 0) { + fprintf(stderr, "Short records at the end of a block were not read\n"); + return 11; + } + + if (check_fuzzy_frame_without_nul() != 0) { + fprintf(stderr, "Fuzzy open found a PVD in a frame without one\n"); + return 12; + } + return 0; }