Skip to content

Commit 3f49677

Browse files
authored
Merge pull request #180 from DenverM80/64_bit_offsets
Fix request query params for 64bit values
2 parents 374c0d6 + e89cfa0 commit 3f49677

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed

src/ds3.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <libxml/parser.h>
2727
#include <libxml/xmlmemory.h>
2828
#include <errno.h>
29+
#include <inttypes.h>
2930

3031
#include "ds3.h"
3132
#include "ds3_request.h"
@@ -45,6 +46,13 @@
4546
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
4647
#endif
4748

49+
//The max size of an uint32_t should be 10 characters + NULL
50+
static const char UNSIGNED_LONG_BASE_10[] = "4294967296";
51+
static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10) + 1;
52+
//The max size of an uint64_t should be 20 characters + NULL
53+
static const char UNSIGNED_LONG_LONG_BASE_10[] = "18446744073709551615";
54+
static const unsigned int UNSIGNED_LONG_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_LONG_BASE_10) + 1;
55+
4856
static char* _get_ds3_bucket_acl_permission_str(ds3_bucket_acl_permission input) {
4957
if (input == DS3_BUCKET_ACL_PERMISSION_LIST) {
5058
return "LIST";
@@ -1010,9 +1018,6 @@ void ds3_client_free(ds3_client* client) {
10101018
}
10111019

10121020

1013-
static const char UNSIGNED_LONG_BASE_10[] = "4294967296";
1014-
static const unsigned int UNSIGNED_LONG_BASE_10_STR_LEN = sizeof(UNSIGNED_LONG_BASE_10);
1015-
10161021
typedef struct {
10171022
char* buff;
10181023
size_t size;
@@ -1150,9 +1155,9 @@ static void _set_query_param_flag(const ds3_request* _request, const char* key,
11501155
}
11511156

11521157
static void _set_query_param_uint64_t(const ds3_request* _request, const char* key, uint64_t value) {
1153-
char string_buffer[UNSIGNED_LONG_BASE_10_STR_LEN];
1158+
char string_buffer[UNSIGNED_LONG_LONG_BASE_10_STR_LEN];
11541159
memset(string_buffer, 0, sizeof(string_buffer));
1155-
snprintf(string_buffer, sizeof(string_buffer), "%lu", value);
1160+
snprintf(string_buffer, sizeof(string_buffer), "%"PRIu64, value);
11561161
_set_query_param(_request, key, string_buffer);
11571162
}
11581163

@@ -3579,10 +3584,9 @@ static ds3_error* _get_request_xml_nodes(
35793584
return NULL;
35803585
}
35813586

3582-
#define LENGTH_BUFF_SIZE 21
35833587

35843588
static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_response* obj_list, object_list_type list_type, ds3_job_chunk_client_processing_order_guarantee order) {
3585-
char size_buff[LENGTH_BUFF_SIZE]; //The max size of an uint64_t should be 20 characters
3589+
char size_buff[UNSIGNED_LONG_LONG_BASE_10_STR_LEN];
35863590
xmlDocPtr doc;
35873591
ds3_bulk_object_response* obj;
35883592
xmlNodePtr objects_node, object_node;
@@ -3598,7 +3602,7 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp
35983602

35993603
for (obj_index = 0; obj_index < obj_list->num_objects; obj_index++) {
36003604
obj = obj_list->objects[obj_index];
3601-
g_snprintf(size_buff, sizeof(char) * LENGTH_BUFF_SIZE, "%llu", (unsigned long long int) obj->length);
3605+
g_snprintf(size_buff, sizeof(char) * UNSIGNED_LONG_LONG_BASE_10_STR_LEN, "%"PRIu64, obj->length);
36023606

36033607
object_node = xmlNewNode(NULL, (xmlChar*) "Object");
36043608
xmlAddChild(objects_node, object_node);
@@ -3615,7 +3619,7 @@ static xmlDocPtr _generate_xml_bulk_objects_list(const ds3_bulk_object_list_resp
36153619
}
36163620

36173621
static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_response* mpu_list) {
3618-
char size_buff[LENGTH_BUFF_SIZE]; //The max size of an uint64_t should be 20 characters
3622+
char size_buff[UNSIGNED_LONG_LONG_BASE_10_STR_LEN]; //The max size of an uint64_t should be 20 characters
36193623
xmlDocPtr doc;
36203624
ds3_multipart_upload_part_response* part;
36213625
xmlNodePtr parts_node, part_node;
@@ -3631,7 +3635,7 @@ static xmlDocPtr _generate_xml_complete_mpu(const ds3_complete_multipart_upload_
36313635
part_node = xmlNewNode(NULL, (xmlChar*) "Part");
36323636
xmlAddChild(parts_node, part_node);
36333637

3634-
g_snprintf(size_buff, sizeof(char) * LENGTH_BUFF_SIZE, "%d", part->part_number);
3638+
g_snprintf(size_buff, sizeof(char) * UNSIGNED_LONG_LONG_BASE_10_STR_LEN, "%d", part->part_number);
36353639
xmlNewTextChild(part_node, NULL, (xmlChar*) "PartNumber", (xmlChar*) size_buff);
36363640

36373641
xmlNewTextChild(part_node, NULL, (xmlChar*) "ETag", (xmlChar*) part->etag->value);

src/ds3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ds3_string_multimap.h"
3131

3232
#ifdef __cplusplus
33+
#define __STDC_FORMAT_MACROS
3334
extern "C" {
3435
#endif
3536

test/bulk_put.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <glib.h>
2020
#include <sys/stat.h>
2121
#include <boost/test/unit_test.hpp>
22+
#include <inttypes.h>
2223
#include "ds3.h"
2324
#include "ds3_net.h"
2425
#include "test.h"
@@ -228,7 +229,56 @@ BOOST_AUTO_TEST_CASE( put_utf_object_name ) {
228229
ds3_request_free(request);
229230
ds3_bulk_object_list_response_free(obj_list);
230231
handle_error(error);
232+
ds3_master_object_list_response_free(bulk_response);
233+
234+
clear_bucket(client, bucket_name);
235+
free_client(client);
236+
}
237+
238+
BOOST_AUTO_TEST_CASE( put_64bit_object_sizes ) {
239+
printf("-----Testing PUT objects with 64bit object sizes in name-------\n");
240+
241+
uint64_t test_objects_size = 429496729600; // 400gb > 32bit
242+
const char* bucket_name = "test_64_bit_object_sizes_bucket";
243+
ds3_request* request = NULL;
244+
ds3_master_object_list_response* bulk_response = NULL;
245+
246+
ds3_client* client = get_client();
247+
ds3_error* error = create_bucket_with_data_policy(client, bucket_name, ids.data_policy_id->value);
248+
249+
// Create obj_list with 1 folder with UTF-8 characters
250+
ds3_bulk_object_list_response* obj_list = ds3_init_bulk_object_list();
251+
GPtrArray* ds3_bulk_object_response_array = g_ptr_array_new();
252+
253+
ds3_bulk_object_response* obj1 = g_new0(ds3_bulk_object_response, 1);
254+
obj1->name = ds3_str_init("max_size_obj_1");
255+
obj1->length = test_objects_size;
256+
g_ptr_array_add(ds3_bulk_object_response_array, obj1);
257+
ds3_bulk_object_response* obj2 = g_new0(ds3_bulk_object_response, 1);
258+
obj2->name = ds3_str_init("max_size_obj_2");
259+
obj2->length = test_objects_size;
260+
g_ptr_array_add(ds3_bulk_object_response_array, obj2);
261+
262+
obj_list->objects = (ds3_bulk_object_response**)ds3_bulk_object_response_array->pdata;
263+
obj_list->num_objects = ds3_bulk_object_response_array->len;
264+
g_ptr_array_free(ds3_bulk_object_response_array, FALSE);
265+
266+
request = ds3_init_put_bulk_job_spectra_s3_request(bucket_name, obj_list);
267+
error = ds3_put_bulk_job_spectra_s3_request(client, request, &bulk_response);
268+
ds3_request_free(request);
269+
ds3_bulk_object_list_response_free(obj_list);
270+
handle_error(error);
271+
272+
BOOST_CHECK_EQUAL(bulk_response->num_objects, 14);
231273

274+
BOOST_CHECK_EQUAL(bulk_response->objects[0]->objects[0]->length, 68719476736);
275+
BOOST_CHECK_EQUAL(bulk_response->objects[0]->objects[0]->offset, 0);
276+
277+
BOOST_CHECK_EQUAL(bulk_response->objects[13]->objects[0]->length, 17179869184);
278+
BOOST_CHECK_EQUAL(bulk_response->objects[13]->objects[0]->offset, 412316860416);
279+
280+
ds3_master_object_list_response_free(bulk_response);
232281
clear_bucket(client, bucket_name);
233282
free_client(client);
234283
}
284+

test/metadata_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE( put_metadata_using_get_object_retrieval ) {
391391
ds3_metadata_entry* metadata_entry;
392392
const char* file_name[1] = {"resources/beowulf.txt"};
393393
ds3_client* client = get_client();
394-
const char* bucket_name = "get_object_metadata_test";
394+
const char* bucket_name = "put_metadata_using_get_object_retrieval";
395395
FILE* file;
396396

397397
ds3_error* error = create_bucket_with_data_policy(client, bucket_name, ids.data_policy_id->value);
@@ -405,6 +405,7 @@ BOOST_AUTO_TEST_CASE( put_metadata_using_get_object_retrieval ) {
405405
handle_error(error);
406406

407407
request = ds3_init_put_object_request(bucket_name, "resources/beowulf.txt", obj_list->objects[0]->length);
408+
ds3_request_set_job(request, bulk_response->job_id->value);
408409
file = fopen(obj_list->objects[0]->name->value, "r");
409410

410411
ds3_request_set_metadata(request, "name", "value");

test/search_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE( get_folder_and_objects ) {
244244
BOOST_AUTO_TEST_CASE( get_incorrect_bucket_name ) {
245245
ds3_client* client = get_client();
246246
ds3_s3_object_list_response* response;
247-
const char* bucket_name = "search_bucket_test";
247+
const char* bucket_name = "search_incorrect_bucket_test";
248248
populate_with_objects(client, bucket_name);
249249

250250
ds3_request* request = ds3_init_get_objects_details_spectra_s3_request();

0 commit comments

Comments
 (0)