Skip to content

Commit

Permalink
Merge pull request #40 from chen-honggang/dev/crash-fix
Browse files Browse the repository at this point in the history
fix crash in cos_resumable_download_file()
  • Loading branch information
chen-honggang authored Jul 11, 2022
2 parents cfbb044 + 3eb7b54 commit c8b4dd2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cos_c_sdk/cos_resumable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,9 +1192,10 @@ cos_status_t *cos_resumable_download_file_without_cp(cos_request_options_t *opti
}
file_size = cos_atoi64(value);
crc64_str = apr_table_get(resp_headers, COS_HASH_CRC64_ECMA);
part_num = cos_get_part_num(file_size, part_size);

// checkpoint
checkpoint = cos_create_checkpoint_content(parent_pool);
checkpoint = cos_create_checkpoint_content_with_partnum(parent_pool, part_num);
cos_build_download_checkpoint(options->pool, checkpoint, filepath, object->data, file_size, "", "", part_size);

// Open and truncate the file
Expand All @@ -1208,7 +1209,6 @@ cos_status_t *cos_resumable_download_file_without_cp(cos_request_options_t *opti
apr_file_close(fb->file);

// init download params
part_num = cos_get_part_num(file_size, part_size);
parts = (cos_checkpoint_part_t *)cos_palloc(parent_pool, sizeof(cos_checkpoint_part_t) * part_num);
cos_build_parts(file_size, part_size, parts);
results = (cos_part_task_result_t *)cos_palloc(parent_pool, sizeof(cos_part_task_result_t) * part_num);
Expand Down Expand Up @@ -1360,9 +1360,10 @@ cos_status_t *cos_resumable_download_file_with_cp(cos_request_options_t *options
return ret;
}
file_size = cos_atoi64(object_size_str);
part_num = cos_get_part_num(file_size, part_size);

// checkpoint
checkpoint = cos_create_checkpoint_content(parent_pool);
checkpoint = cos_create_checkpoint_content_with_partnum(parent_pool, part_num);
if (cos_does_file_exist(checkpoint_path, parent_pool)) {
apr_finfo_t tmp_finfo;
if (COSE_OK == cos_load_checkpoint(parent_pool, checkpoint_path, checkpoint) &&
Expand Down Expand Up @@ -1398,7 +1399,6 @@ cos_status_t *cos_resumable_download_file_with_cp(cos_request_options_t *options
apr_file_close(fb->file);

// init download params
part_num = cos_get_part_num(file_size, part_size);
parts = (cos_checkpoint_part_t *)cos_palloc(parent_pool, sizeof(cos_checkpoint_part_t) * part_num);
cos_get_checkpoint_undo_parts(checkpoint, &part_num, parts, &consume_bytes);
results = (cos_part_task_result_t *)cos_palloc(parent_pool, sizeof(cos_part_task_result_t) * part_num);
Expand Down
2 changes: 1 addition & 1 deletion cos_c_sdk/cos_sys_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ typedef apr_array_header_t cos_array_header_t;
#define CR (char) 13
#define CRLF "\x0d\x0a"

#define COS_VERSION "5.0.11"
#define COS_VERSION "5.0.14"
#define COS_VER "cos-sdk-c/" COS_VERSION

#define COS_HTTP_PREFIX "http://"
Expand Down
15 changes: 15 additions & 0 deletions cos_c_sdk/cos_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,21 @@ cos_checkpoint_t *cos_create_checkpoint_content(cos_pool_t *p)
return cp;
}

cos_checkpoint_t *cos_create_checkpoint_content_with_partnum(cos_pool_t *p, int part_num)
{
cos_checkpoint_t *cp;
cp = (cos_checkpoint_t *)cos_pcalloc(p, sizeof(cos_checkpoint_t));
cp->parts = (cos_checkpoint_part_t *)cos_pcalloc(p, sizeof(cos_checkpoint_part_t) * cos_max(part_num, COS_MAX_PART_NUM));
cos_str_set(&cp->md5, "");
cos_str_set(&cp->file_path, "");
cos_str_set(&cp->file_md5, "");
cos_str_set(&cp->object_name, "");
cos_str_set(&cp->object_last_modified, "");
cos_str_set(&cp->object_etag, "");
cos_str_set(&cp->upload_id, "");
return cp;
}

cos_resumable_clt_params_t *cos_create_resumable_clt_params_content(cos_pool_t *p, int64_t part_size, int32_t thread_num,
int enable_checkpoint, const char *checkpoint_path)
{
Expand Down
1 change: 1 addition & 0 deletions cos_c_sdk/cos_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ cos_live_channel_configuration_t *cos_create_live_channel_configuration_content(
* @return cos checkpoint content
**/
cos_checkpoint_t *cos_create_checkpoint_content(cos_pool_t *p);
cos_checkpoint_t *cos_create_checkpoint_content_with_partnum(cos_pool_t *p, int part_num);

/**
* @brief create cos resumable clt params content
Expand Down

0 comments on commit c8b4dd2

Please sign in to comment.