From 16863755be913835363039f6f72d37fdc31d85c0 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sun, 20 Feb 2011 12:10:26 +0100 Subject: [PATCH] Installed a check for miscalculated ECMA-119 tree size. --- libisofs/ecma119.c | 31 +++++++++++++++++++++++++++++-- libisofs/ecma119.h | 6 ++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index c74d490..9911345 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -329,6 +329,9 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer) image start and not for the partition */; } + + target->tree_end_block = target->curblock; + return ISO_SUCCESS; } @@ -874,6 +877,7 @@ int ecma119_writer_write_data(IsoImageWriter *writer) { int ret; Ecma119Image *t; + uint32_t curblock; if (writer == NULL) { return ISO_ASSERT_FAILURE; @@ -891,6 +895,20 @@ int ecma119_writer_write_data(IsoImageWriter *writer) if (ret < 0) return ret; } + + curblock = (t->bytes_written / 2048) + t->ms_block; + if (curblock != t->tree_end_block) { + char msg[100]; + + sprintf(msg, + "Calculated and written ECMA-119 tree end differ: %lu <> %lu", + (unsigned long) t->tree_end_block, + (unsigned long) curblock); + iso_msgs_submit(0, msg, 0, "WARNING", 0); + + t->tree_end_block = 1;/* Mark for harsher reaction at end of writing */ + } + return ISO_SUCCESS; } @@ -1405,6 +1423,12 @@ void *write_function(void *arg) Eventually free target */ ecma119_image_free(target); + if (target->tree_end_block == 1) { + iso_msgs_submit(0, + "Image is most likely damaged. Calculated/written block address mismatch.", + 0, "FATAL", 0); + } + #ifdef Libisofs_with_pthread_exiT pthread_exit(NULL); #else @@ -1739,6 +1763,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) target->mipsel_p_filesz = 0; target->empty_file_block = 0; + target->tree_end_block = 0; target->wthread_is_running = 0; @@ -2281,6 +2306,8 @@ int iso_write(Ecma119Image *target, void *buf, size_t count) /* reader cancelled */ return ISO_CANCELED; } + if (ret < 0) + return ret; if (target->checksum_ctx != NULL) { /* Add to image checksum */ target->checksum_counter += count; @@ -2292,7 +2319,7 @@ int iso_write(Ecma119Image *target, void *buf, size_t count) return ret; /* total size is 0 when writing the overwrite buffer */ - if (ret > 0 && (target->total_size != (off_t) 0)){ + if (target->total_size != (off_t) 0){ unsigned int kbw, kbt; int percent; @@ -2309,7 +2336,7 @@ int iso_write(Ecma119Image *target, void *buf, size_t count) } } - return ret; + return ISO_SUCCESS; } int iso_write_opts_new(IsoWriteOpts **opts, int profile) diff --git a/libisofs/ecma119.h b/libisofs/ecma119.h index e02da14..2c4b9aa 100644 --- a/libisofs/ecma119.h +++ b/libisofs/ecma119.h @@ -525,6 +525,12 @@ struct ecma119_image */ uint32_t empty_file_block; + /* + * The calculated block address after ECMA-119 tree and eventual + * tree checksum tag. + */ + uint32_t tree_end_block; + /* * number of dirs in ECMA-119 tree, computed together with dir position, * and needed for path table computation in a efficient way