Skip to content

Commit d210b0a

Browse files
committed
Fix integer overflow in write_tree
1 parent 784c1a4 commit d210b0a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

extract-xiso.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,8 +1711,9 @@ int free_dir_node_avl( void *in_dir_node_avl, void *in_context, long in_depth )
17111711
int write_tree( dir_node_avl *in_avl, write_tree_context *in_context, int in_depth ) {
17121712
xoff_t pos;
17131713
write_tree_context context;
1714+
xoff_t dir_start = (xoff_t)in_avl->start_sector * XISO_SECTOR_SIZE;
17141715
int err = 0, pad;
1715-
char sector[ XISO_SECTOR_SIZE ];
1716+
char sector[XISO_SECTOR_SIZE];
17161717

17171718
if ( in_avl->subdirectory ) {
17181719
if ( in_context->path ) { if ( asprintf( &context.path, "%s%s%c", in_context->path, in_avl->filename, PATH_CHAR ) == -1 ) mem_err(); }
@@ -1734,7 +1735,7 @@ int write_tree( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep
17341735
if ( ! err ) err = avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) write_file, &context, k_prefix, 0 );
17351736
if ( ! err ) err = avl_traverse_depth_first( in_avl->subdirectory, (traversal_callback) write_tree, &context, k_prefix, 0 );
17361737

1737-
if (!err && lseek(in_context->xiso, (xoff_t)in_avl->start_sector * XISO_SECTOR_SIZE, SEEK_SET) == -1) seek_err();
1738+
if (!err && lseek(in_context->xiso, dir_start, SEEK_SET) == -1) seek_err();
17381739
if (!err) err = avl_traverse_depth_first(in_avl->subdirectory, (traversal_callback)write_directory, in_context, k_prefix, 0);
17391740
if (!err && (pos = lseek(in_context->xiso, 0, SEEK_CUR)) == -1) seek_err();
17401741
if (!err && (pad = (int)((XISO_SECTOR_SIZE - (pos % XISO_SECTOR_SIZE)) % XISO_SECTOR_SIZE))) {
@@ -1747,7 +1748,7 @@ int write_tree( dir_node_avl *in_avl, write_tree_context *in_context, int in_dep
17471748
}
17481749
} else {
17491750
memset(sector, XISO_PAD_BYTE, XISO_SECTOR_SIZE);
1750-
if ((pos = lseek(in_context->xiso, in_avl->start_sector * XISO_SECTOR_SIZE, SEEK_SET)) == -1) seek_err();
1751+
if ((pos = lseek(in_context->xiso, dir_start, SEEK_SET)) == -1) seek_err();
17511752
if (!err && write(in_context->xiso, sector, XISO_SECTOR_SIZE) != XISO_SECTOR_SIZE) write_err();
17521753
}
17531754

0 commit comments

Comments
 (0)