Skip to content

Commit

Permalink
Fix metadata of blank file upload
Browse files Browse the repository at this point in the history
- Distinguish blank file field from empty file contents
- Fix inability to upload empty file of zero size
- Prevent empty temp file creation for blank file field
- Remove irrelevant MIME type of blank file field
- Resolve #2778 Irrelevant metadata for blank file upload field
  • Loading branch information
sshymko committed Aug 26, 2019
1 parent 1a3a7b5 commit 62d18c6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions swoole_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,23 @@ static int multipart_body_on_header_value(multipart_parser* p, const char *at, s
tmp = http_trim_double_quote(value_buf, &value_len);

add_assoc_stringl(z_multipart_header, "name", tmp, value_len);
if (value_len == 0)
{
add_assoc_long(z_multipart_header, "error", HTTP_UPLOAD_ERR_NO_FILE);
}

ctx->current_multipart_header = z_multipart_header;
}
zval_ptr_dtor(&tmp_array);
}

if (strncasecmp(headername, "content-type", header_len) == 0 && ctx->current_multipart_header)
else if (strncasecmp(headername, "content-type", header_len) == 0 && ctx->current_multipart_header)
{
add_assoc_stringl(ctx->current_multipart_header, "type", (char * ) at, length);
zval *z_multipart_header = ctx->current_multipart_header;
zval *zerr = zend_hash_str_find(Z_ARRVAL_P(z_multipart_header), ZEND_STRL("error"));
if (zerr && Z_TYPE_P(zerr) == IS_LONG && Z_LVAL_P(zerr) == HTTP_UPLOAD_ERR_OK)
{
add_assoc_stringl(ctx->current_multipart_header, "type", (char * ) at, length);
}
}

efree(headername);
Expand Down Expand Up @@ -696,10 +704,6 @@ static int multipart_body_on_data_end(multipart_parser* p)
{
long size = swoole_file_get_size((FILE *) p->fp);
add_assoc_long(z_multipart_header, "size", size);
if (size == 0)
{
add_assoc_long(z_multipart_header, "error", HTTP_UPLOAD_ERR_NO_FILE);
}

fclose((FILE *) p->fp);
p->fp = NULL;
Expand Down

0 comments on commit 62d18c6

Please sign in to comment.