1
- /* Copyright (c) 2003, 2010 , Oracle and/or its affiliates. All rights reserved.
1
+ /* Copyright (c) 2003, 2015 , Oracle and/or its affiliates. All rights reserved.
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
@@ -28,15 +28,15 @@ static char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
28
28
* Maximum length base64_needed_encoded_length()
29
29
* can handle without overflow.
30
30
*/
31
- int
31
+ uint64
32
32
base64_encode_max_arg_length ()
33
33
{
34
- #if (SIZEOF_INT == 8 )
34
+ #if (SIZEOF_VOIDP == 8 )
35
35
/*
36
36
6827690988321067803 -> 9223372036854775805
37
37
6827690988321067804 -> -9223372036854775807
38
38
*/
39
- return 0x5EC0D4C77B03531BLL
39
+ return 0x5EC0D4C77B03531BLL ;
40
40
#else
41
41
/*
42
42
1589695686 -> 2147483646
@@ -47,10 +47,11 @@ base64_encode_max_arg_length()
47
47
}
48
48
49
49
50
- int
51
- base64_needed_encoded_length (int length_of_data )
50
+ uint64
51
+ base64_needed_encoded_length (uint64 length_of_data )
52
52
{
53
- int nb_base64_chars ;
53
+ uint64 nb_base64_chars ;
54
+ if (length_of_data == 0 ) return 1 ;
54
55
nb_base64_chars = (length_of_data + 2 ) / 3 * 4 ;
55
56
56
57
return
@@ -64,21 +65,21 @@ base64_needed_encoded_length(int length_of_data)
64
65
* Maximum length base64_needed_decoded_length()
65
66
* can handle without overflow.
66
67
*/
67
- int
68
+ uint64
68
69
base64_decode_max_arg_length ()
69
70
{
70
- #if (SIZEOF_INT == 8 )
71
+ #if (SIZEOF_VOIDP == 8 )
71
72
return 0x2AAAAAAAAAAAAAAALL ;
72
73
#else
73
74
return 0x2AAAAAAA ;
74
75
#endif
75
76
}
76
77
77
78
78
- int
79
- base64_needed_decoded_length (int length_of_encoded_data )
79
+ uint64
80
+ base64_needed_decoded_length (uint64 length_of_encoded_data )
80
81
{
81
- return (int ) ceil (length_of_encoded_data * 3 / 4 );
82
+ return (uint64 ) ceil (length_of_encoded_data * 3 / 4 );
82
83
}
83
84
84
85
@@ -313,7 +314,7 @@ my_base64_decoder_getch(MY_BASE64_DECODER *decoder)
313
314
* @flags flags e.g. allow multiple chunks
314
315
* @return Number of bytes written at 'dst', or -1 in case of failure
315
316
*/
316
- int
317
+ int64
317
318
base64_decode (const char * src_base , size_t len ,
318
319
void * dst , const char * * end_ptr , int flags )
319
320
{
@@ -379,16 +380,31 @@ main(void)
379
380
size_t k , l ;
380
381
size_t dst_len ;
381
382
size_t needed_length ;
382
-
383
- for (i = 0 ; i < 500 ; i ++ )
383
+ char * src ;
384
+ char * s ;
385
+ char * str ;
386
+ char * dst ;
387
+ const char * end_ptr ;
388
+ size_t src_len ;
389
+
390
+ for (i = 0 ; i <= 500 ; i ++ )
384
391
{
385
392
/* Create source data */
386
- const size_t src_len = rand () % 1000 + 1 ;
393
+ if (i == 500 )
394
+ {
395
+ #if (SIZEOF_VOIDP == 8 )
396
+ printf ("Test case for base64 max event length: 2119594243\n" );
397
+ src_len = 2119594243 ;
398
+ #else
399
+ printf ("Test case for base64 max event length: 536870912\n" );
400
+ src_len = 536870912 ;
401
+ #endif
402
+ }
403
+ else
404
+ src_len = rand () % 1000 + 1 ;
387
405
388
- char * src = (char * ) malloc (src_len );
389
- char * s = src ;
390
- char * str ;
391
- char * dst ;
406
+ src = (char * ) malloc (src_len );
407
+ s = src ;
392
408
393
409
require (src );
394
410
for (j = 0 ; j < src_len ; j ++ )
@@ -409,7 +425,7 @@ main(void)
409
425
/* Decode */
410
426
dst = (char * ) malloc (base64_needed_decoded_length (strlen (str )));
411
427
require (dst );
412
- dst_len = base64_decode (str , strlen (str ), dst , NULL );
428
+ dst_len = base64_decode (str , strlen (str ), dst , & end_ptr , 0 );
413
429
require (dst_len == src_len );
414
430
415
431
if (memcmp (src , dst , src_len ) != 0 )
@@ -437,6 +453,9 @@ main(void)
437
453
(uint ) src_len , (uint ) dst_len );
438
454
require (0 );
439
455
}
456
+ free (src );
457
+ free (str );
458
+ free (dst );
440
459
}
441
460
printf ("Test succeeded.\n" );
442
461
return 0 ;
0 commit comments