Installed a check for miscalculated ECMA-119 tree size.

This commit is contained in:
Thomas Schmitt 2011-02-20 12:10:26 +01:00
parent b25ac0f52d
commit 16863755be
2 changed files with 35 additions and 2 deletions

View File

@ -329,6 +329,9 @@ int ecma119_writer_compute_data_blocks(IsoImageWriter *writer)
image start and not for the partition */; image start and not for the partition */;
} }
target->tree_end_block = target->curblock;
return ISO_SUCCESS; return ISO_SUCCESS;
} }
@ -874,6 +877,7 @@ int ecma119_writer_write_data(IsoImageWriter *writer)
{ {
int ret; int ret;
Ecma119Image *t; Ecma119Image *t;
uint32_t curblock;
if (writer == NULL) { if (writer == NULL) {
return ISO_ASSERT_FAILURE; return ISO_ASSERT_FAILURE;
@ -891,6 +895,20 @@ int ecma119_writer_write_data(IsoImageWriter *writer)
if (ret < 0) if (ret < 0)
return ret; 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; return ISO_SUCCESS;
} }
@ -1405,6 +1423,12 @@ void *write_function(void *arg)
Eventually free target */ Eventually free target */
ecma119_image_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 #ifdef Libisofs_with_pthread_exiT
pthread_exit(NULL); pthread_exit(NULL);
#else #else
@ -1739,6 +1763,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
target->mipsel_p_filesz = 0; target->mipsel_p_filesz = 0;
target->empty_file_block = 0; target->empty_file_block = 0;
target->tree_end_block = 0;
target->wthread_is_running = 0; target->wthread_is_running = 0;
@ -2281,6 +2306,8 @@ int iso_write(Ecma119Image *target, void *buf, size_t count)
/* reader cancelled */ /* reader cancelled */
return ISO_CANCELED; return ISO_CANCELED;
} }
if (ret < 0)
return ret;
if (target->checksum_ctx != NULL) { if (target->checksum_ctx != NULL) {
/* Add to image checksum */ /* Add to image checksum */
target->checksum_counter += count; target->checksum_counter += count;
@ -2292,7 +2319,7 @@ int iso_write(Ecma119Image *target, void *buf, size_t count)
return ret; return ret;
/* total size is 0 when writing the overwrite buffer */ /* 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; unsigned int kbw, kbt;
int percent; 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) int iso_write_opts_new(IsoWriteOpts **opts, int profile)

View File

@ -525,6 +525,12 @@ struct ecma119_image
*/ */
uint32_t empty_file_block; 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, * number of dirs in ECMA-119 tree, computed together with dir position,
* and needed for path table computation in a efficient way * and needed for path table computation in a efficient way