isofs: Fix handling of directories with tight blocks

Thomas has reported that after commit b2eb2e2886 ("isofs: Drop support
of directory entries straddling blocks") some isofs images of Fedora
miss some entries in some directories. The problem is triggered when
directory entries are packed in a block in such a way that they exactly
fit the block (which BTW mkisofs doesn't do so I didn't catch this bug
when testing with my images). Fix readdir and lookup code to properly
transition to the next block when directory block is tightly packed.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2535353
Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Reported-by: Matthias Goergens <matthias.goergens@gmail.com>
Fixes: b2eb2e2886 ("isofs: Drop support of directory entries straddling blocks")
Reviewed-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
Jan Kara 2026-09-22 12:41:02 +02:00
parent 704340f1cd
commit 883b776abe
2 changed files with 17 additions and 19 deletions

View File

@ -110,25 +110,21 @@ static int do_isofs_readdir(struct inode *inode, struct file *file,
return 0;
}
de = (struct iso_directory_record *) (bh->b_data + offset);
de_len = *(unsigned char *)de;
de = (struct iso_directory_record *)(bh->b_data + offset);
/*
* If the length byte is zero, we should move on to the next
* CDROM sector. If we are at the end of the directory, we
* kick out of the while loop.
* If we are at the end of a block (or at its zero-padded
* tail), move on to the next CDROM sector. If we are at the
* end of the directory, we'll abort the while loop.
*/
if (de_len == 0) {
if (offset >= bufsize || de->length[0] == 0) {
brelse(bh);
bh = NULL;
ctx->pos = (ctx->pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1);
block = ctx->pos >> bufbits;
block++;
ctx->pos = (loff_t)block << bufbits;
offset = 0;
continue;
}
de_len = de->length[0];
block_saved = block;
offset_saved = offset;
offset += de_len;

View File

@ -74,18 +74,20 @@ isofs_find_entry(struct inode *dir, struct dentry *dentry,
return 0;
}
de = (struct iso_directory_record *) (bh->b_data + offset);
de_len = *(unsigned char *) de;
if (!de_len) {
de = (struct iso_directory_record *)(bh->b_data + offset);
/*
* If we are at the end of the block or at its zero-padded
* tail, move to the next block.
*/
if (offset >= bufsize || de->length[0] == 0) {
brelse(bh);
bh = NULL;
f_pos = (f_pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1);
block = f_pos >> bufbits;
block++;
f_pos = block << bufbits;
offset = 0;
continue;
}
de_len = de->length[0];
block_saved = bh->b_blocknr;
offset_saved = offset;
offset += de_len;