From 4598057553e67c999a279f8c47f40eb84ff98258 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 24 Feb 2025 15:46:27 +0000 Subject: [PATCH] each tag ioctx now keeps its own copy of the ec3_tag_info describing it this fixes an issue where pointers to ec3_tag_info would become invalid when the b_buffer containing them was resized. --- src/image.c | 10 +++++----- src/image.h | 8 -------- src/tag.c | 4 ++-- src/tag.h | 10 +++++++++- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/image.c b/src/image.c index 1fd0ea3..8900320 100644 --- a/src/image.c +++ b/src/image.c @@ -16,12 +16,12 @@ B_BTREE_DEFINE_SIMPLE_GET( struct ec3_tag_ioctx, uint64_t, io_node, - io_tag_info->tag_ident, + io_tag_info.tag_ident, get_opened_tag) B_BTREE_DEFINE_SIMPLE_INSERT( struct ec3_tag_ioctx, io_node, - io_tag_info->tag_ident, + io_tag_info.tag_ident, put_opened_tag) static enum ec3_status decode_header( @@ -729,7 +729,7 @@ enum ec3_status ec3_image_ioctx_open_tag_by_type( tag_ioctx->io_mode = mode; tag_ioctx->io_parent = image; - tag_ioctx->io_tag_info = tag_info; + tag_ioctx->io_tag_info = *tag_info; tag_ioctx->io_f_image = b_file_retain(image->io_main); if (mode & EC3_TAG_IO_WRITE) { @@ -791,7 +791,7 @@ enum ec3_status ec3_image_ioctx_open_tag_by_id( tag_ioctx->io_mode = mode; tag_ioctx->io_parent = image; - tag_ioctx->io_tag_info = tag_info; + tag_ioctx->io_tag_info = *tag_info; tag_ioctx->io_f_image = b_file_retain(image->io_main); if (mode & EC3_TAG_IO_WRITE) { @@ -862,7 +862,7 @@ enum ec3_status ec3_image_ioctx_create_tag( tag_ioctx->io_mode = mode; tag_ioctx->io_parent = image; - tag_ioctx->io_tag_info = tag_info; + tag_ioctx->io_tag_info = *tag_info; tag_ioctx->io_f_image = b_file_retain(image->io_main); status = init_tag_ioctx_create(image, tag_info, tag_ioctx); diff --git a/src/image.h b/src/image.h index 7700eae..691d031 100644 --- a/src/image.h +++ b/src/image.h @@ -44,14 +44,6 @@ struct ec3_image_info { uint64_t img_id; }; -struct ec3_tag_info { - unsigned long tag_type; - unsigned long tag_flags; - unsigned long tag_checksum; - unsigned long long tag_ident; - unsigned long long tag_total_length; -}; - struct ec3_extent_info { unsigned long long ex_owner; unsigned long ex_logical_cluster; diff --git a/src/tag.c b/src/tag.c index 0582c9a..9e41f0a 100644 --- a/src/tag.c +++ b/src/tag.c @@ -142,7 +142,7 @@ enum ec3_status ec3_tag_ioctx_read_cluster( size_t physical_cluster_id = 0; status = ec3_image_ioctx_cluster_logical_to_physical( tag->io_parent, - tag->io_tag_info, + &tag->io_tag_info, cluster_id, &physical_cluster_id); @@ -276,7 +276,7 @@ enum ec3_status ec3_tag_ioctx_get_nr_clusters( for (size_t i = 0; i < nr_extents; i++) { const struct ec3_extent_info *x = &extents[i]; - if (x->ex_owner != tag->io_tag_info->tag_ident) { + if (x->ex_owner != tag->io_tag_info.tag_ident) { continue; } diff --git a/src/tag.h b/src/tag.h index 09b9595..6e86cbb 100644 --- a/src/tag.h +++ b/src/tag.h @@ -20,6 +20,14 @@ enum ec3_tag_ioctx_mode { EC3_TAG_IO_CLOSED = 0x10u, }; +struct ec3_tag_info { + unsigned long tag_type; + unsigned long tag_flags; + unsigned long tag_checksum; + unsigned long long tag_ident; + unsigned long long tag_total_length; +}; + struct ec3_tag_ioctx { struct ec3_image_ioctx *io_parent; b_btree_node io_node; @@ -32,7 +40,7 @@ struct ec3_tag_ioctx { size_t io_cluster_data_offset; /* this points to memory belonging to ec3_image_ioctx */ - const struct ec3_tag_info *io_tag_info; + struct ec3_tag_info io_tag_info; /* io_f_rotag is a reference to the main image file. a data and cluster * table offset will be used to read clusters from the image if the tag