2293
2283
/* my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr()); */
2296
if (stat_info.st_size > (long) current_session->variables.max_allowed_packet)
2286
if (stat_info.st_size > (long) current_thd->variables.max_allowed_packet)
2298
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2288
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2299
2289
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
2300
2290
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
2301
func_name(), current_session->variables.max_allowed_packet);
2291
func_name(), current_thd->variables.max_allowed_packet);
2304
2294
if (tmp_value.alloc(stat_info.st_size))
2306
2296
if ((file = my_open(file_name->c_ptr(), O_RDONLY, MYF(0))) < 0)
2308
if (my_read(file, (unsigned char*) tmp_value.ptr(), stat_info.st_size, MYF(MY_NABP)))
2298
if (my_read(file, (uchar*) tmp_value.ptr(), stat_info.st_size, MYF(MY_NABP)))
2310
2300
my_close(file, MYF(0));
2492
int64_t Item_func_uncompressed_length::val_int()
2495
String *res= args[0]->val_str(&value);
2499
return 0; /* purecov: inspected */
2502
if (res->is_empty()) return 0;
2505
res->ptr() using is safe because we have tested that string is not empty,
2506
res->c_ptr() is not used because:
2507
- we do not need \0 terminated string to get first 4 bytes
2508
- c_ptr() tests simbol after string end (uninitialiozed memory) which
2511
return uint4korr(res->ptr()) & 0x3FFFFFFF;
2514
#ifdef HAVE_COMPRESS
2517
String *Item_func_compress::val_str(String *str)
2519
int err= Z_OK, code;
2523
char *tmp, *last_char;
2526
if (!(res= args[0]->val_str(str)))
2532
if (res->is_empty()) return res;
2535
Citation from zlib.h (comment for compress function):
2537
Compresses the source buffer into the destination buffer. sourceLen is
2538
the byte length of the source buffer. Upon entry, destLen is the total
2539
size of the destination buffer, which must be at least 0.1% larger than
2540
sourceLen plus 12 bytes.
2541
We assume here that the buffer can't grow more than .25 %.
2543
new_size= res->length() + res->length() / 5 + 12;
2545
// Check new_size overflow: new_size <= res->length()
2546
if (((uint32_t) (new_size+5) <= res->length()) ||
2547
buffer.realloc((uint32_t) new_size + 4 + 1))
2553
body= ((Byte*)buffer.ptr()) + 4;
2555
// As far as we have checked res->is_empty() we can use ptr()
2556
if ((err= compress(body, &new_size,
2557
(const Bytef*)res->ptr(), res->length())) != Z_OK)
2559
code= err==Z_MEM_ERROR ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_BUF_ERROR;
2560
push_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
2565
tmp= (char*)buffer.ptr(); // int4store is a macro; avoid side effects
2566
int4store(tmp, res->length() & 0x3FFFFFFF);
2568
/* This is to ensure that things works for CHAR fields, which trim ' ': */
2569
last_char= ((char*)body)+new_size-1;
2570
if (*last_char == ' ')
2576
buffer.length((uint32_t)new_size + 4);
2581
String *Item_func_uncompress::val_str(String *str)
2584
String *res= args[0]->val_str(str);
2592
if (res->is_empty())
2595
/* If length is less than 4 bytes, data is corrupt */
2596
if (res->length() <= 4)
2598
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2599
ER_ZLIB_Z_DATA_ERROR,
2600
ER(ER_ZLIB_Z_DATA_ERROR));
2604
/* Size of uncompressed data is stored as first 4 bytes of field */
2605
new_size= uint4korr(res->ptr()) & 0x3FFFFFFF;
2606
if (new_size > current_thd->variables.max_allowed_packet)
2608
push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2609
ER_TOO_BIG_FOR_UNCOMPRESS,
2610
ER(ER_TOO_BIG_FOR_UNCOMPRESS),
2611
current_thd->variables.max_allowed_packet);
2614
if (buffer.realloc((uint32_t)new_size))
2617
if ((err= uncompress((Byte*)buffer.ptr(), &new_size,
2618
((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
2620
buffer.length((uint32_t) new_size);
2624
code= ((err == Z_BUF_ERROR) ? ER_ZLIB_Z_BUF_ERROR :
2625
((err == Z_MEM_ERROR) ? ER_ZLIB_Z_MEM_ERROR : ER_ZLIB_Z_DATA_ERROR));
2626
push_warning(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, code, ER(code));
2636
DCE 1.1: Remote Procedure Call,
2637
Open Group Technical Standard Document Number C706, October 1997,
2638
(supersedes C309 DCE: Remote Procedure Call 8/1994,
2639
which was basis for ISO/IEC 11578:1996 specification)
2642
static struct rand_struct uuid_rand;
2643
static uint nanoseq;
2644
static uint64_t uuid_time=0;
2645
static char clock_seq_and_node_str[]="-0000-000000000000";
2648
number of 100-nanosecond intervals between
2649
1582-10-15 00:00:00.00 and 1970-01-01 00:00:00.00.
2651
#define UUID_TIME_OFFSET ((uint64_t) 141427 * 24 * 60 * 60 * 1000 * 10 )
2653
#define UUID_VERSION 0x1000
2654
#define UUID_VARIANT 0x8000
2656
static void tohex(char *to, uint from, uint len)
2661
*--to= _dig_vec_lower[from & 15];
2666
static void set_clock_seq_str()
2668
uint16_t clock_seq= ((uint)(my_rnd(&uuid_rand)*16383)) | UUID_VARIANT;
2669
tohex(clock_seq_and_node_str+1, clock_seq, 4);
2504
2673
String *Item_func_uuid::val_str(String *str)
2509
/* 36 characters for uuid string +1 for NULL */
2677
THD *thd= current_thd;
2679
pthread_mutex_lock(&LOCK_uuid_generator);
2680
if (! uuid_time) /* first UUID() call. initializing data */
2682
ulong tmp= sql_rnd();
2685
if (my_gethwaddr(mac))
2687
/* purecov: begin inspected */
2689
generating random "hardware addr"
2690
and because specs explicitly specify that it should NOT correlate
2691
with a clock_seq value (initialized random below), we use a separate
2694
randominit(&uuid_rand, tmp + (ulong) thd, tmp + (ulong)global_query_id);
2695
for (i=0; i < (int)sizeof(mac); i++)
2696
mac[i]=(uchar)(my_rnd(&uuid_rand)*255);
2699
s=clock_seq_and_node_str+sizeof(clock_seq_and_node_str)-1;
2700
for (i=sizeof(mac)-1 ; i>=0 ; i--)
2702
*--s=_dig_vec_lower[mac[i] & 15];
2703
*--s=_dig_vec_lower[mac[i] >> 4];
2705
randominit(&uuid_rand, tmp + (ulong) server_start_time,
2706
tmp + (ulong) thd->status_var.bytes_sent);
2707
set_clock_seq_str();
2710
uint64_t tv=my_getsystime() + UUID_TIME_OFFSET + nanoseq;
2711
if (unlikely(tv < uuid_time))
2712
set_clock_seq_str();
2713
else if (unlikely(tv == uuid_time))
2715
/* special protection from low-res system clocks */
2726
assert(tv > uuid_time);
2729
pthread_mutex_unlock(&LOCK_uuid_generator);
2731
uint32_t time_low= (uint32_t) (tv & 0xFFFFFFFF);
2732
uint16_t time_mid= (uint16_t) ((tv >> 32) & 0xFFFF);
2733
uint16_t time_hi_and_version= (uint16_t) ((tv >> 48) | UUID_VERSION);
2735
str->realloc(UUID_LENGTH+1);
2736
str->length(UUID_LENGTH);
2512
2737
str->set_charset(system_charset_info);
2513
uuid_string= (char *) str->ptr();
2514
uuid_generate_time(uu);
2515
uuid_unparse(uu, uuid_string);
2738
s=(char *) str->ptr();
2740
tohex(s, time_low, 8);
2741
tohex(s+9, time_mid, 4);
2742
tohex(s+14, time_hi_and_version, 4);
2743
stpcpy(s+18, clock_seq_and_node_str);