summaryrefslogtreecommitdiff
path: root/src/e2e.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/e2e.c')
-rw-r--r--src/e2e.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/e2e.c b/src/e2e.c
index 5ac9f6c..d842fd8 100644
--- a/src/e2e.c
+++ b/src/e2e.c
@@ -86,6 +86,12 @@ static int make_pointer(const struct e2e_data *data, const char *pos,
static int read_fundus(struct e2e_data *data, const char *cursor,
struct e2e_image *image)
{
+ if (cursor + image->width * image->height > data->end) {
+ errorf("Fundus image at %td ends past the end of file.\n",
+ cursor - data->start);
+ return 1;
+ }
+
// This cast is _technically_ illegal, but I can't think of a way in
// which this would cause problems in practice.
image->fundus = (const uint8_t*)cursor;
@@ -96,6 +102,12 @@ static int read_fundus(struct e2e_data *data, const char *cursor,
static int read_tomogram(struct e2e_data *data, const char *cursor,
struct e2e_image *image)
{
+ if (cursor + image->width * image->height * 2 > data->end) {
+ errorf("Tomogram image at %td ends past the end of file.\n",
+ cursor - data->start);
+ return 1;
+ }
+
image->tomogram = calloc(image->width * image->height, sizeof(float));
if (!image->tomogram)
return ENOMEM;
@@ -407,17 +419,29 @@ static int post_process(struct e2e_data *data)
eli_for(dir, data->dirs, data_list)
for (size_t i = 0; i < dir->num_entries; i++) {
struct e2e_entry *entry = dir->entries + i;
+ struct e2e_series *series;
struct e2e_slice *slice;
rv = ensure_slice(data, entry->patient_id, entry->study_id,
entry->series_id, entry->slice_id,
- NULL, NULL, NULL, &slice);
+ NULL, NULL, &series, &slice);
if (rv)
return rv;
- if (slice && entry->has_chunk
- && entry->chunk.type == E2E_CHUNK_IMAGE)
- slice->image = &entry->chunk.image;
+ if (entry->has_chunk && entry->chunk.type == E2E_CHUNK_IMAGE) {
+ struct e2e_image *image = &entry->chunk.image;
+
+ if (slice &&
+ entry->chunk.image.type == E2E_IMAGE_TOMOGRAM)
+ slice->image = image;
+
+ if (series &&
+ entry->chunk.image.type == E2E_IMAGE_FUNDUS) {
+ eli_append(&series->fundi, image,
+ series_fundi_list);
+ series->num_fundi++;
+ }
+ }
}
return 0;