Skip to content

Commit

Permalink
Merge pull request #45 from beetlebugorg/bugfix/empty-blob
Browse files Browse the repository at this point in the history
Return 400 bad request if image blob is NULL
  • Loading branch information
JC authored Mar 12, 2022
2 parents a099026 + 145548c commit 49700ac
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/mod_dims.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ dims_send_image(dims_request_rec *d)
d->r->status = HTTP_INTERNAL_SERVER_ERROR;
}

if (blob == NULL) {
d->r->status = HTTP_BAD_REQUEST;
}

if(d->status == DIMS_SUCCESS && d->fetch_http_status == 200 && d->client_config) {

// if the src image has a cache_control header, parse out the max-age
Expand Down Expand Up @@ -897,11 +901,16 @@ dims_send_image(dims_request_rec *d)
MagickSizeType image_size = 0;
MagickGetImageLength(d->wand, &image_size);

char content_length[256] = "";
snprintf(content_length, sizeof(content_length), "%zu", (size_t)image_size);
apr_table_set(d->r->headers_out, "Content-Length", content_length);
if (blob != NULL) {
char content_length[256] = "";
snprintf(content_length, sizeof(content_length), "%zu", (size_t)image_size);
apr_table_set(d->r->headers_out, "Content-Length", content_length);

ap_rwrite(blob, length, d->r);
} else {
apr_table_set(d->r->headers_out, "Content-Length", "0");
}

ap_rwrite(blob, length, d->r);
ap_rflush(d->r);

MagickRelinquishMemory(blob);
Expand Down

0 comments on commit 49700ac

Please sign in to comment.