VYPR
Critical severityNVD Advisory· Published Jan 6, 2021· Updated Aug 4, 2024

CVE-2020-26759

CVE-2020-26759

Description

clickhouse-driver before 0.1.5 has a buffer overflow vulnerability that allows a malicious server to crash or execute arbitrary code on a database client.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

clickhouse-driver before 0.1.5 has a buffer overflow vulnerability that allows a malicious server to crash or execute arbitrary code on a database client.

Vulnerability

Overview The clickhouse-driver Python library before version 0.1.5 contains a buffer overflow vulnerability arising from improper handling of integer types in the BufferedReader class. The vulnerable code used signed Py_ssize_t variables for buffer positions and sizes, allowing an attacker to craft a server response that triggers an overflow condition [1][4]. This issue affects Cython-defined functions responsible for reading data from the network buffer.

Exploitation

Method An attacker controlling a malicious ClickHouse server can send a specially crafted response to a client using the vulnerable driver. The overflow occurs when the client processes server data, as the read, read_into_buffer, and read_strings methods do not correctly handle large unsigned values [4]. No authentication is required from the server side, and the attack vector is network-based, requiring only that the client connects to the malicious server.

Impact

Successful exploitation can cause a crash of the client application or lead to arbitrary code execution on the client machine. The official advisory describes the impact as allowing a malicious server to "trigger a crash or execute arbitrary code" [1][2]. This poses a significant risk to applications that connect to untrusted ClickHouse servers.

Mitigation

Users should upgrade to clickhouse-driver version 0.1.5 or later, which fixes the buffer overflow by changing the affected integer types to unsigned long long and adding proper bounds checks [4]. The vulnerability is listed in the GitHub Advisory Database as GHSA-vgv5-cxvh-vfxh [1]. No public exploit code is mentioned in the references.

AI Insight generated on May 21, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
clickhouse-driverPyPI
< 0.1.50.1.5

Affected products

3

Patches

2
d708ed548e1d

Fix read_varint overflow

https://github.com/mymarilyn/clickhouse-driverKonstantin LebedevSep 11, 2020via ghsa
3 files changed · +210 159
  • clickhouse_driver/varint.c+181 147 modified
    @@ -1064,8 +1064,11 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
     static void __Pyx_AddTraceback(const char *funcname, int c_line,
                                    int py_line, const char *filename);
     
    +/* CIntToPy.proto */
    +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value);
    +
     /* CIntFromPy.proto */
    -static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *);
    +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *);
     
     /* CIntToPy.proto */
     static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
    @@ -1196,8 +1199,8 @@ static const char __pyx_k_write[] = "write";
     static const char __pyx_k_number[] = "number";
     static const char __pyx_k_result[] = "result";
     static const char __pyx_k_num_buf[] = "num_buf";
    -static const char __pyx_k_towrite[] = "towrite";
     static const char __pyx_k_read_one[] = "read_one";
    +static const char __pyx_k_to_write[] = "to_write";
     static const char __pyx_k_read_varint[] = "read_varint";
     static const char __pyx_k_write_varint[] = "write_varint";
     static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
    @@ -1218,10 +1221,10 @@ static PyObject *__pyx_n_s_read_varint;
     static PyObject *__pyx_n_s_result;
     static PyObject *__pyx_n_s_shift;
     static PyObject *__pyx_n_s_test;
    -static PyObject *__pyx_n_s_towrite;
    +static PyObject *__pyx_n_s_to_write;
     static PyObject *__pyx_n_s_write;
     static PyObject *__pyx_n_s_write_varint;
    -static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED PyObject *__pyx_self, Py_ssize_t __pyx_v_number, PyObject *__pyx_v_buf); /* proto */
    +static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED PyObject *__pyx_self, unsigned PY_LONG_LONG __pyx_v_number, PyObject *__pyx_v_buf); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f); /* proto */
     static PyObject *__pyx_tuple_;
     static PyObject *__pyx_tuple__3;
    @@ -1232,7 +1235,7 @@ static PyObject *__pyx_codeobj__4;
     /* "clickhouse_driver/varint.pyx":4
      * 
      * 
    - * def write_varint(Py_ssize_t number, buf):             # <<<<<<<<<<<<<<
    + * def write_varint(unsigned long long number, buf):             # <<<<<<<<<<<<<<
      *     """
      *     Writes integer of variable length using LEB128.
      */
    @@ -1242,7 +1245,7 @@ static PyObject *__pyx_pw_17clickhouse_driver_6varint_1write_varint(PyObject *__
     static char __pyx_doc_17clickhouse_driver_6varint_write_varint[] = "\n    Writes integer of variable length using LEB128.\n    ";
     static PyMethodDef __pyx_mdef_17clickhouse_driver_6varint_1write_varint = {"write_varint", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_17clickhouse_driver_6varint_1write_varint, METH_VARARGS|METH_KEYWORDS, __pyx_doc_17clickhouse_driver_6varint_write_varint};
     static PyObject *__pyx_pw_17clickhouse_driver_6varint_1write_varint(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
    -  Py_ssize_t __pyx_v_number;
    +  unsigned PY_LONG_LONG __pyx_v_number;
       PyObject *__pyx_v_buf = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
    @@ -1282,7 +1285,7 @@ static PyObject *__pyx_pw_17clickhouse_driver_6varint_1write_varint(PyObject *__
           values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
           values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
         }
    -    __pyx_v_number = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_number == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 4, __pyx_L3_error)
    +    __pyx_v_number = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[0]); if (unlikely((__pyx_v_number == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 4, __pyx_L3_error)
         __pyx_v_buf = values[1];
       }
       goto __pyx_L4_argument_unpacking_done;
    @@ -1300,9 +1303,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_6varint_1write_varint(PyObject *__
       return __pyx_r;
     }
     
    -static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED PyObject *__pyx_self, Py_ssize_t __pyx_v_number, PyObject *__pyx_v_buf) {
    -  Py_ssize_t __pyx_v_i;
    -  unsigned char __pyx_v_towrite;
    +static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED PyObject *__pyx_self, unsigned PY_LONG_LONG __pyx_v_number, PyObject *__pyx_v_buf) {
    +  unsigned char __pyx_v_to_write;
    +  unsigned char __pyx_v_i;
       unsigned char __pyx_v_num_buf[32];
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
    @@ -1316,98 +1319,98 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED
       /* "clickhouse_driver/varint.pyx":8
      *     Writes integer of variable length using LEB128.
      *     """
    - *     cdef Py_ssize_t i = 0             # <<<<<<<<<<<<<<
    - *     cdef unsigned char towrite
    - *     # Py_ssize_t checks integer on function call and
    + *     cdef unsigned char to_write, i = 0             # <<<<<<<<<<<<<<
    + *     # unsigned PY_LONG_LONG checks integer on function call and
    + *     # raises OverflowError if integer overflows unsigned PY_LONG_LONG.
      */
       __pyx_v_i = 0;
     
    -  /* "clickhouse_driver/varint.pyx":15
    +  /* "clickhouse_driver/varint.pyx":14
      *     cdef unsigned char num_buf[32]
      * 
      *     while True:             # <<<<<<<<<<<<<<
    - *         towrite = number & 0x7f
    + *         to_write = number & 0x7f
      *         number >>= 7
      */
       while (1) {
     
    -    /* "clickhouse_driver/varint.pyx":16
    +    /* "clickhouse_driver/varint.pyx":15
      * 
      *     while True:
    - *         towrite = number & 0x7f             # <<<<<<<<<<<<<<
    + *         to_write = number & 0x7f             # <<<<<<<<<<<<<<
      *         number >>= 7
      *         if number:
      */
    -    __pyx_v_towrite = (__pyx_v_number & 0x7f);
    +    __pyx_v_to_write = (__pyx_v_number & 0x7f);
     
    -    /* "clickhouse_driver/varint.pyx":17
    +    /* "clickhouse_driver/varint.pyx":16
      *     while True:
    - *         towrite = number & 0x7f
    + *         to_write = number & 0x7f
      *         number >>= 7             # <<<<<<<<<<<<<<
      *         if number:
    - *             num_buf[i] = towrite | 0x80
    + *             num_buf[i] = to_write | 0x80
      */
         __pyx_v_number = (__pyx_v_number >> 7);
     
    -    /* "clickhouse_driver/varint.pyx":18
    - *         towrite = number & 0x7f
    +    /* "clickhouse_driver/varint.pyx":17
    + *         to_write = number & 0x7f
      *         number >>= 7
      *         if number:             # <<<<<<<<<<<<<<
    - *             num_buf[i] = towrite | 0x80
    + *             num_buf[i] = to_write | 0x80
      *             i += 1
      */
         __pyx_t_1 = (__pyx_v_number != 0);
         if (__pyx_t_1) {
     
    -      /* "clickhouse_driver/varint.pyx":19
    +      /* "clickhouse_driver/varint.pyx":18
      *         number >>= 7
      *         if number:
    - *             num_buf[i] = towrite | 0x80             # <<<<<<<<<<<<<<
    + *             num_buf[i] = to_write | 0x80             # <<<<<<<<<<<<<<
      *             i += 1
      *         else:
      */
    -      (__pyx_v_num_buf[__pyx_v_i]) = (__pyx_v_towrite | 0x80);
    +      (__pyx_v_num_buf[__pyx_v_i]) = (__pyx_v_to_write | 0x80);
     
    -      /* "clickhouse_driver/varint.pyx":20
    +      /* "clickhouse_driver/varint.pyx":19
      *         if number:
    - *             num_buf[i] = towrite | 0x80
    + *             num_buf[i] = to_write | 0x80
      *             i += 1             # <<<<<<<<<<<<<<
      *         else:
    - *             num_buf[i] = towrite
    + *             num_buf[i] = to_write
      */
           __pyx_v_i = (__pyx_v_i + 1);
     
    -      /* "clickhouse_driver/varint.pyx":18
    - *         towrite = number & 0x7f
    +      /* "clickhouse_driver/varint.pyx":17
    + *         to_write = number & 0x7f
      *         number >>= 7
      *         if number:             # <<<<<<<<<<<<<<
    - *             num_buf[i] = towrite | 0x80
    + *             num_buf[i] = to_write | 0x80
      *             i += 1
      */
           goto __pyx_L5;
         }
     
    -    /* "clickhouse_driver/varint.pyx":22
    +    /* "clickhouse_driver/varint.pyx":21
      *             i += 1
      *         else:
    - *             num_buf[i] = towrite             # <<<<<<<<<<<<<<
    + *             num_buf[i] = to_write             # <<<<<<<<<<<<<<
      *             i += 1
      *             break
      */
         /*else*/ {
    -      (__pyx_v_num_buf[__pyx_v_i]) = __pyx_v_towrite;
    +      (__pyx_v_num_buf[__pyx_v_i]) = __pyx_v_to_write;
     
    -      /* "clickhouse_driver/varint.pyx":23
    +      /* "clickhouse_driver/varint.pyx":22
      *         else:
    - *             num_buf[i] = towrite
    + *             num_buf[i] = to_write
      *             i += 1             # <<<<<<<<<<<<<<
      *             break
      * 
      */
           __pyx_v_i = (__pyx_v_i + 1);
     
    -      /* "clickhouse_driver/varint.pyx":24
    - *             num_buf[i] = towrite
    +      /* "clickhouse_driver/varint.pyx":23
    + *             num_buf[i] = to_write
      *             i += 1
      *             break             # <<<<<<<<<<<<<<
      * 
    @@ -1419,16 +1422,16 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED
       }
       __pyx_L4_break:;
     
    -  /* "clickhouse_driver/varint.pyx":26
    +  /* "clickhouse_driver/varint.pyx":25
      *             break
      * 
      *     buf.write(PyBytes_FromStringAndSize(<char *>num_buf, i))             # <<<<<<<<<<<<<<
      * 
      * 
      */
    -  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_buf, __pyx_n_s_write); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_buf, __pyx_n_s_write); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 25, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
    -  __pyx_t_4 = PyBytes_FromStringAndSize(((char *)__pyx_v_num_buf), __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 26, __pyx_L1_error)
    +  __pyx_t_4 = PyBytes_FromStringAndSize(((char *)__pyx_v_num_buf), __pyx_v_i); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 25, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_4);
       __pyx_t_5 = NULL;
       if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    @@ -1443,15 +1446,15 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED
       __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_4) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4);
       __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
       __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    -  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
    +  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
       __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     
       /* "clickhouse_driver/varint.pyx":4
      * 
      * 
    - * def write_varint(Py_ssize_t number, buf):             # <<<<<<<<<<<<<<
    + * def write_varint(unsigned long long number, buf):             # <<<<<<<<<<<<<<
      *     """
      *     Writes integer of variable length using LEB128.
      */
    @@ -1472,7 +1475,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED
       return __pyx_r;
     }
     
    -/* "clickhouse_driver/varint.pyx":29
    +/* "clickhouse_driver/varint.pyx":28
      * 
      * 
      * def read_varint(f):             # <<<<<<<<<<<<<<
    @@ -1496,50 +1499,50 @@ static PyObject *__pyx_pw_17clickhouse_driver_6varint_3read_varint(PyObject *__p
     }
     
     static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_f) {
    -  Py_ssize_t __pyx_v_shift;
    -  Py_ssize_t __pyx_v_result;
    -  unsigned char __pyx_v_i;
    +  unsigned char __pyx_v_shift;
    +  unsigned PY_LONG_LONG __pyx_v_i;
    +  unsigned PY_LONG_LONG __pyx_v_result;
       PyObject *__pyx_v_read_one = NULL;
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    -  unsigned char __pyx_t_4;
    +  unsigned PY_LONG_LONG __pyx_t_4;
       int __pyx_t_5;
       __Pyx_RefNannySetupContext("read_varint", 0);
     
    -  /* "clickhouse_driver/varint.pyx":33
    +  /* "clickhouse_driver/varint.pyx":32
      *     Reads integer of variable length using LEB128.
      *     """
    - *     cdef Py_ssize_t shift = 0             # <<<<<<<<<<<<<<
    - *     cdef Py_ssize_t result = 0
    - *     cdef unsigned char i
    + *     cdef unsigned char shift = 0             # <<<<<<<<<<<<<<
    + *     cdef unsigned long long i, result = 0
    + * 
      */
       __pyx_v_shift = 0;
     
    -  /* "clickhouse_driver/varint.pyx":34
    +  /* "clickhouse_driver/varint.pyx":33
      *     """
    - *     cdef Py_ssize_t shift = 0
    - *     cdef Py_ssize_t result = 0             # <<<<<<<<<<<<<<
    - *     cdef unsigned char i
    + *     cdef unsigned char shift = 0
    + *     cdef unsigned long long i, result = 0             # <<<<<<<<<<<<<<
      * 
    + *     read_one = f.read_one
      */
       __pyx_v_result = 0;
     
    -  /* "clickhouse_driver/varint.pyx":37
    - *     cdef unsigned char i
    +  /* "clickhouse_driver/varint.pyx":35
    + *     cdef unsigned long long i, result = 0
      * 
      *     read_one = f.read_one             # <<<<<<<<<<<<<<
      * 
      *     while True:
      */
    -  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_read_one); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 37, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_read_one); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_v_read_one = __pyx_t_1;
       __pyx_t_1 = 0;
     
    -  /* "clickhouse_driver/varint.pyx":39
    +  /* "clickhouse_driver/varint.pyx":37
      *     read_one = f.read_one
      * 
      *     while True:             # <<<<<<<<<<<<<<
    @@ -1548,7 +1551,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
      */
       while (1) {
     
    -    /* "clickhouse_driver/varint.pyx":40
    +    /* "clickhouse_driver/varint.pyx":38
      * 
      *     while True:
      *         i = read_one()             # <<<<<<<<<<<<<<
    @@ -1568,14 +1571,14 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
         }
         __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2);
         __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    -    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error)
    +    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    -    __pyx_t_4 = __Pyx_PyInt_As_unsigned_char(__pyx_t_1); if (unlikely((__pyx_t_4 == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 40, __pyx_L1_error)
    +    __pyx_t_4 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_4 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 38, __pyx_L1_error)
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
         __pyx_v_i = __pyx_t_4;
     
    -    /* "clickhouse_driver/varint.pyx":41
    +    /* "clickhouse_driver/varint.pyx":39
      *     while True:
      *         i = read_one()
      *         result |= (i & 0x7f) << shift             # <<<<<<<<<<<<<<
    @@ -1584,7 +1587,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
      */
         __pyx_v_result = (__pyx_v_result | ((__pyx_v_i & 0x7f) << __pyx_v_shift));
     
    -    /* "clickhouse_driver/varint.pyx":42
    +    /* "clickhouse_driver/varint.pyx":40
      *         i = read_one()
      *         result |= (i & 0x7f) << shift
      *         shift += 7             # <<<<<<<<<<<<<<
    @@ -1593,7 +1596,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
      */
         __pyx_v_shift = (__pyx_v_shift + 7);
     
    -    /* "clickhouse_driver/varint.pyx":43
    +    /* "clickhouse_driver/varint.pyx":41
      *         result |= (i & 0x7f) << shift
      *         shift += 7
      *         if i < 0x80:             # <<<<<<<<<<<<<<
    @@ -1603,7 +1606,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
         __pyx_t_5 = ((__pyx_v_i < 0x80) != 0);
         if (__pyx_t_5) {
     
    -      /* "clickhouse_driver/varint.pyx":44
    +      /* "clickhouse_driver/varint.pyx":42
      *         shift += 7
      *         if i < 0x80:
      *             break             # <<<<<<<<<<<<<<
    @@ -1612,7 +1615,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
      */
           goto __pyx_L4_break;
     
    -      /* "clickhouse_driver/varint.pyx":43
    +      /* "clickhouse_driver/varint.pyx":41
      *         result |= (i & 0x7f) << shift
      *         shift += 7
      *         if i < 0x80:             # <<<<<<<<<<<<<<
    @@ -1623,19 +1626,19 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
       }
       __pyx_L4_break:;
     
    -  /* "clickhouse_driver/varint.pyx":46
    +  /* "clickhouse_driver/varint.pyx":44
      *             break
      * 
      *     return result             # <<<<<<<<<<<<<<
      */
       __Pyx_XDECREF(__pyx_r);
    -  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_r = __pyx_t_1;
       __pyx_t_1 = 0;
       goto __pyx_L0;
     
    -  /* "clickhouse_driver/varint.pyx":29
    +  /* "clickhouse_driver/varint.pyx":28
      * 
      * 
      * def read_varint(f):             # <<<<<<<<<<<<<<
    @@ -1718,7 +1721,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
       {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1},
       {&__pyx_n_s_shift, __pyx_k_shift, sizeof(__pyx_k_shift), 0, 0, 1, 1},
       {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
    -  {&__pyx_n_s_towrite, __pyx_k_towrite, sizeof(__pyx_k_towrite), 0, 0, 1, 1},
    +  {&__pyx_n_s_to_write, __pyx_k_to_write, sizeof(__pyx_k_to_write), 0, 0, 1, 1},
       {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
       {&__pyx_n_s_write_varint, __pyx_k_write_varint, sizeof(__pyx_k_write_varint), 0, 0, 1, 1},
       {0, 0, 0, 0, 0, 0, 0}
    @@ -1734,26 +1737,26 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
       /* "clickhouse_driver/varint.pyx":4
      * 
      * 
    - * def write_varint(Py_ssize_t number, buf):             # <<<<<<<<<<<<<<
    + * def write_varint(unsigned long long number, buf):             # <<<<<<<<<<<<<<
      *     """
      *     Writes integer of variable length using LEB128.
      */
    -  __pyx_tuple_ = PyTuple_Pack(5, __pyx_n_s_number, __pyx_n_s_buf, __pyx_n_s_i, __pyx_n_s_towrite, __pyx_n_s_num_buf); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 4, __pyx_L1_error)
    +  __pyx_tuple_ = PyTuple_Pack(5, __pyx_n_s_number, __pyx_n_s_buf, __pyx_n_s_to_write, __pyx_n_s_i, __pyx_n_s_num_buf); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 4, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_tuple_);
       __Pyx_GIVEREF(__pyx_tuple_);
       __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple_, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_n_s_write_varint, 4, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 4, __pyx_L1_error)
     
    -  /* "clickhouse_driver/varint.pyx":29
    +  /* "clickhouse_driver/varint.pyx":28
      * 
      * 
      * def read_varint(f):             # <<<<<<<<<<<<<<
      *     """
      *     Reads integer of variable length using LEB128.
      */
    -  __pyx_tuple__3 = PyTuple_Pack(5, __pyx_n_s_f, __pyx_n_s_shift, __pyx_n_s_result, __pyx_n_s_i, __pyx_n_s_read_one); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 29, __pyx_L1_error)
    +  __pyx_tuple__3 = PyTuple_Pack(5, __pyx_n_s_f, __pyx_n_s_shift, __pyx_n_s_i, __pyx_n_s_result, __pyx_n_s_read_one); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 28, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_tuple__3);
       __Pyx_GIVEREF(__pyx_tuple__3);
    -  __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_n_s_read_varint, 29, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 29, __pyx_L1_error)
    +  __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_clickhouse_driver_varint_pyx, __pyx_n_s_read_varint, 28, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 28, __pyx_L1_error)
       __Pyx_RefNannyFinishContext();
       return 0;
       __pyx_L1_error:;
    @@ -2058,7 +2061,7 @@ if (!__Pyx_RefNanny) {
       /* "clickhouse_driver/varint.pyx":4
      * 
      * 
    - * def write_varint(Py_ssize_t number, buf):             # <<<<<<<<<<<<<<
    + * def write_varint(unsigned long long number, buf):             # <<<<<<<<<<<<<<
      *     """
      *     Writes integer of variable length using LEB128.
      */
    @@ -2067,16 +2070,16 @@ if (!__Pyx_RefNanny) {
       if (PyDict_SetItem(__pyx_d, __pyx_n_s_write_varint, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
    -  /* "clickhouse_driver/varint.pyx":29
    +  /* "clickhouse_driver/varint.pyx":28
      * 
      * 
      * def read_varint(f):             # <<<<<<<<<<<<<<
      *     """
      *     Reads integer of variable length using LEB128.
      */
    -  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_6varint_3read_varint, NULL, __pyx_n_s_clickhouse_driver_varint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error)
    +  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_17clickhouse_driver_6varint_3read_varint, NULL, __pyx_n_s_clickhouse_driver_varint); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_varint, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L1_error)
    +  if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_varint, __pyx_t_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
       /* "clickhouse_driver/varint.pyx":1
    @@ -2900,20 +2903,51 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
             return (target_type) value;\
         }
     
    +/* CIntToPy */
    +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) {
    +    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG) ((unsigned PY_LONG_LONG) 0 - (unsigned PY_LONG_LONG) 1), const_zero = (unsigned PY_LONG_LONG) 0;
    +    const int is_unsigned = neg_one > const_zero;
    +    if (is_unsigned) {
    +        if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) {
    +            return PyInt_FromLong((long) value);
    +        } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) {
    +            return PyLong_FromUnsignedLong((unsigned long) value);
    +#ifdef HAVE_LONG_LONG
    +        } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
    +            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
    +#endif
    +        }
    +    } else {
    +        if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) {
    +            return PyInt_FromLong((long) value);
    +#ifdef HAVE_LONG_LONG
    +        } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
    +            return PyLong_FromLongLong((PY_LONG_LONG) value);
    +#endif
    +        }
    +    }
    +    {
    +        int one = 1; int little = (int)*(unsigned char *)&one;
    +        unsigned char *bytes = (unsigned char *)&value;
    +        return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG),
    +                                     little, !is_unsigned);
    +    }
    +}
    +
     /* CIntFromPy */
    -static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) {
    -    const unsigned char neg_one = (unsigned char) ((unsigned char) 0 - (unsigned char) 1), const_zero = (unsigned char) 0;
    +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) {
    +    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG) ((unsigned PY_LONG_LONG) 0 - (unsigned PY_LONG_LONG) 1), const_zero = (unsigned PY_LONG_LONG) 0;
         const int is_unsigned = neg_one > const_zero;
     #if PY_MAJOR_VERSION < 3
         if (likely(PyInt_Check(x))) {
    -        if (sizeof(unsigned char) < sizeof(long)) {
    -            __PYX_VERIFY_RETURN_INT(unsigned char, long, PyInt_AS_LONG(x))
    +        if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) {
    +            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x))
             } else {
                 long val = PyInt_AS_LONG(x);
                 if (is_unsigned && unlikely(val < 0)) {
                     goto raise_neg_overflow;
                 }
    -            return (unsigned char) val;
    +            return (unsigned PY_LONG_LONG) val;
             }
         } else
     #endif
    @@ -2922,32 +2956,32 @@ static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) {
     #if CYTHON_USE_PYLONG_INTERNALS
                 const digit* digits = ((PyLongObject*)x)->ob_digit;
                 switch (Py_SIZE(x)) {
    -                case  0: return (unsigned char) 0;
    -                case  1: __PYX_VERIFY_RETURN_INT(unsigned char, digit, digits[0])
    +                case  0: return (unsigned PY_LONG_LONG) 0;
    +                case  1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0])
                     case 2:
    -                    if (8 * sizeof(unsigned char) > 1 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) >= 2 * PyLong_SHIFT) {
    -                            return (unsigned char) (((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                             }
                         }
                         break;
                     case 3:
    -                    if (8 * sizeof(unsigned char) > 2 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) >= 3 * PyLong_SHIFT) {
    -                            return (unsigned char) (((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                             }
                         }
                         break;
                     case 4:
    -                    if (8 * sizeof(unsigned char) > 3 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) >= 4 * PyLong_SHIFT) {
    -                            return (unsigned char) (((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                             }
                         }
                         break;
    @@ -2961,86 +2995,86 @@ static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) {
                 {
                     int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                     if (unlikely(result < 0))
    -                    return (unsigned char) -1;
    +                    return (unsigned PY_LONG_LONG) -1;
                     if (unlikely(result == 1))
                         goto raise_neg_overflow;
                 }
     #endif
    -            if (sizeof(unsigned char) <= sizeof(unsigned long)) {
    -                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, unsigned long, PyLong_AsUnsignedLong(x))
    +            if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x))
     #ifdef HAVE_LONG_LONG
    -            } else if (sizeof(unsigned char) <= sizeof(unsigned PY_LONG_LONG)) {
    -                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
    +            } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
     #endif
                 }
             } else {
     #if CYTHON_USE_PYLONG_INTERNALS
                 const digit* digits = ((PyLongObject*)x)->ob_digit;
                 switch (Py_SIZE(x)) {
    -                case  0: return (unsigned char) 0;
    -                case -1: __PYX_VERIFY_RETURN_INT(unsigned char, sdigit, (sdigit) (-(sdigit)digits[0]))
    -                case  1: __PYX_VERIFY_RETURN_INT(unsigned char,  digit, +digits[0])
    +                case  0: return (unsigned PY_LONG_LONG) 0;
    +                case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0]))
    +                case  1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG,  digit, +digits[0])
                     case -2:
    -                    if (8 * sizeof(unsigned char) - 1 > 1 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) {
    -                            return (unsigned char) (((unsigned char)-1)*(((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
                             }
                         }
                         break;
                     case 2:
    -                    if (8 * sizeof(unsigned char) > 1 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) {
    -                            return (unsigned char) ((((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
                             }
                         }
                         break;
                     case -3:
    -                    if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) {
    -                            return (unsigned char) (((unsigned char)-1)*(((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
                             }
                         }
                         break;
                     case 3:
    -                    if (8 * sizeof(unsigned char) > 2 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) {
    -                            return (unsigned char) ((((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) ((((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
                             }
                         }
                         break;
                     case -4:
    -                    if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) - 1 > 4 * PyLong_SHIFT) {
    -                            return (unsigned char) (((unsigned char)-1)*(((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
                             }
                         }
                         break;
                     case 4:
    -                    if (8 * sizeof(unsigned char) > 3 * PyLong_SHIFT) {
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) {
                             if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
    -                            __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    -                        } else if (8 * sizeof(unsigned char) - 1 > 4 * PyLong_SHIFT) {
    -                            return (unsigned char) ((((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])));
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) ((((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
                             }
                         }
                         break;
                 }
     #endif
    -            if (sizeof(unsigned char) <= sizeof(long)) {
    -                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, long, PyLong_AsLong(x))
    +            if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x))
     #ifdef HAVE_LONG_LONG
    -            } else if (sizeof(unsigned char) <= sizeof(PY_LONG_LONG)) {
    -                __PYX_VERIFY_RETURN_INT_EXC(unsigned char, PY_LONG_LONG, PyLong_AsLongLong(x))
    +            } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x))
     #endif
                 }
             }
    @@ -3049,7 +3083,7 @@ static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) {
                 PyErr_SetString(PyExc_RuntimeError,
                                 "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
     #else
    -            unsigned char val;
    +            unsigned PY_LONG_LONG val;
                 PyObject *v = __Pyx_PyNumber_IntOrLong(x);
      #if PY_MAJOR_VERSION < 3
                 if (likely(v) && !PyLong_Check(v)) {
    @@ -3069,24 +3103,24 @@ static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) {
                         return val;
                 }
     #endif
    -            return (unsigned char) -1;
    +            return (unsigned PY_LONG_LONG) -1;
             }
         } else {
    -        unsigned char val;
    +        unsigned PY_LONG_LONG val;
             PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
    -        if (!tmp) return (unsigned char) -1;
    -        val = __Pyx_PyInt_As_unsigned_char(tmp);
    +        if (!tmp) return (unsigned PY_LONG_LONG) -1;
    +        val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp);
             Py_DECREF(tmp);
             return val;
         }
     raise_overflow:
         PyErr_SetString(PyExc_OverflowError,
    -        "value too large to convert to unsigned char");
    -    return (unsigned char) -1;
    +        "value too large to convert to unsigned PY_LONG_LONG");
    +    return (unsigned PY_LONG_LONG) -1;
     raise_neg_overflow:
         PyErr_SetString(PyExc_OverflowError,
    -        "can't convert negative value to unsigned char");
    -    return (unsigned char) -1;
    +        "can't convert negative value to unsigned PY_LONG_LONG");
    +    return (unsigned PY_LONG_LONG) -1;
     }
     
     /* CIntToPy */
    
  • clickhouse_driver/varint.pyx+10 12 modified
    @@ -1,25 +1,24 @@
     from cpython cimport Py_INCREF, PyBytes_FromStringAndSize
     
     
    -def write_varint(Py_ssize_t number, buf):
    +def write_varint(unsigned long long number, buf):
         """
         Writes integer of variable length using LEB128.
         """
    -    cdef Py_ssize_t i = 0
    -    cdef unsigned char towrite
    -    # Py_ssize_t checks integer on function call and
    -    # raises OverflowError if integer overflows Py_ssize_t.
    -    # Long enough for handling Py_ssize_t.
    +    cdef unsigned char to_write, i = 0
    +    # unsigned PY_LONG_LONG checks integer on function call and
    +    # raises OverflowError if integer overflows unsigned PY_LONG_LONG.
    +    # Long enough for handling unsigned PY_LONG_LONG.
         cdef unsigned char num_buf[32]
     
         while True:
    -        towrite = number & 0x7f
    +        to_write = number & 0x7f
             number >>= 7
             if number:
    -            num_buf[i] = towrite | 0x80
    +            num_buf[i] = to_write | 0x80
                 i += 1
             else:
    -            num_buf[i] = towrite
    +            num_buf[i] = to_write
                 i += 1
                 break
     
    @@ -30,9 +29,8 @@ def read_varint(f):
         """
         Reads integer of variable length using LEB128.
         """
    -    cdef Py_ssize_t shift = 0
    -    cdef Py_ssize_t result = 0
    -    cdef unsigned char i
    +    cdef unsigned char shift = 0
    +    cdef unsigned long long i, result = 0
     
         read_one = f.read_one
     
    
  • tests/test_varint.py+19 0 added
    @@ -0,0 +1,19 @@
    +from io import BytesIO
    +from unittest import TestCase
    +
    +from clickhouse_driver.varint import read_varint, write_varint
    +
    +
    +class VarIntTestCase(TestCase):
    +    def test_check_not_negative(self):
    +        n = 0x9FFFFFFF
    +
    +        buf = BytesIO()
    +        write_varint(n, buf)
    +        val = buf.getvalue()
    +        self.assertEqual(b'\xFF\xFF\xFF\xFF\t', val)
    +
    +        buf = BytesIO(val)
    +        buf.read_one = lambda: ord(buf.read(1))
    +        m = read_varint(buf)
    +        self.assertEqual(m, n)
    
3e990547e064

Fix malformed read/write in BufferedReader

https://github.com/mymarilyn/clickhouse-driverKonstantin LebedevSep 4, 2020via ghsa
8 files changed · +1266 394
  • clickhouse_driver/bufferedreader.c+541 189 modified
    @@ -1,12 +1,12 @@
    -/* Generated by Cython 0.29.17 */
    +/* Generated by Cython 0.29.21 */
     
     /* BEGIN: Cython Metadata
     {
         "distutils": {
             "depends": [],
             "name": "clickhouse_driver.bufferedreader",
             "sources": [
    -            "clickhouse_driver/bufferedreader.pyx"
    +            "/home/klebedev/work/clickhouse-driver/clickhouse_driver/bufferedreader.pyx"
             ]
         },
         "module_name": "clickhouse_driver.bufferedreader"
    @@ -20,9 +20,9 @@ END: Cython Metadata */
     #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
         #error Cython requires Python 2.6+ or Python 3.3+.
     #else
    -#define CYTHON_ABI "0_29_17"
    -#define CYTHON_HEX_VERSION 0x001D11F0
    -#define CYTHON_FUTURE_DIVISION 1
    +#define CYTHON_ABI "0_29_21"
    +#define CYTHON_HEX_VERSION 0x001D15F0
    +#define CYTHON_FUTURE_DIVISION 0
     #include <stddef.h>
     #ifndef offsetof
       #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
    @@ -448,7 +448,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
       #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
       #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
    +  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
       #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    +  #else
    +  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
    +  #endif
     #else
       #define CYTHON_PEP393_ENABLED 0
       #define PyUnicode_1BYTE_KIND  1
    @@ -511,6 +515,13 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
     #ifndef PySet_CheckExact
       #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
     #endif
    +#if PY_VERSION_HEX >= 0x030900A4
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
    +#else
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
    +#endif
     #if CYTHON_ASSUME_SAFE_MACROS
       #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
     #else
    @@ -550,7 +561,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
     #endif
     #if PY_MAJOR_VERSION >= 3
    -  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
    +  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
     #else
       #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
     #endif
    @@ -591,11 +602,10 @@ static CYTHON_INLINE float __PYX_NAN() {
     #define __Pyx_truncl truncl
     #endif
     
    -
    +#define __PYX_MARK_ERR_POS(f_index, lineno) \
    +    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
     #define __PYX_ERR(f_index, lineno, Ln_error) \
    -{ \
    -  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
    -}
    +    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
     
     #ifndef __PYX_EXTERN_C
       #ifdef __cplusplus
    @@ -835,13 +845,13 @@ struct __pyx_obj_17clickhouse_driver_14bufferedreader_CompressedBufferedReader;
      * 
      * 
      * cdef class BufferedReader(object):             # <<<<<<<<<<<<<<
    - *     cdef public Py_ssize_t position, current_buffer_size
    + *     cdef public unsigned long long position, current_buffer_size
      *     cdef public bytearray buffer
      */
     struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader {
       PyObject_HEAD
    -  Py_ssize_t position;
    -  Py_ssize_t current_buffer_size;
    +  unsigned PY_LONG_LONG position;
    +  unsigned PY_LONG_LONG current_buffer_size;
       PyObject *buffer;
     };
     
    @@ -1262,12 +1272,18 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
     static void __Pyx_AddTraceback(const char *funcname, int c_line,
                                    int py_line, const char *filename);
     
    +/* CIntToPy.proto */
    +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value);
    +
     /* CIntToPy.proto */
     static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char value);
     
     /* CIntToPy.proto */
     static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
     
    +/* CIntFromPy.proto */
    +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *);
    +
     /* CIntFromPy.proto */
     static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
     
    @@ -1458,7 +1474,7 @@ static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xef;
     static PyObject *__pyx_n_s_MemoryError;
     static PyObject *__pyx_n_s_NotImplementedError;
     static PyObject *__pyx_n_s_PickleError;
    -static PyObject *__pyx_kp_u_Unexpected_EOF_while_reading_byt;
    +static PyObject *__pyx_kp_s_Unexpected_EOF_while_reading_byt;
     static PyObject *__pyx_n_s_UnicodeDecodeError;
     static PyObject *__pyx_n_s_bufsize;
     static PyObject *__pyx_n_s_clickhouse_driver_bufferedreader;
    @@ -1497,12 +1513,12 @@ static PyObject *__pyx_kp_s_stringsource;
     static PyObject *__pyx_n_s_super;
     static PyObject *__pyx_n_s_test;
     static PyObject *__pyx_n_s_update;
    -static PyObject *__pyx_kp_u_utf_8;
    +static PyObject *__pyx_kp_s_utf_8;
     static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader___init__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_bufsize); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_2read_into_buffer(CYTHON_UNUSED struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */
    -static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_unread); /* proto */
    +static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_unread); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6read_one(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */
    -static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_n_items, PyObject *__pyx_v_encoding); /* proto */
    +static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_n_items, PyObject *__pyx_v_encoding); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */
     static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size___get__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self); /* proto */
    @@ -1550,6 +1566,9 @@ static PyObject *__pyx_codeobj__7;
     static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
     static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_bufsize = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -1602,6 +1621,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader___init
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":15
    @@ -1721,14 +1743,17 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_2read_into_buffer(CYTHON_UNUSED struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self) {
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_into_buffer", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":23
      * 
      *     def read_into_buffer(self):
      *         raise NotImplementedError             # <<<<<<<<<<<<<<
      * 
    - *     def read(self, Py_ssize_t unread):
    + *     def read(self, unsigned long long unread):
      */
       __Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
       __PYX_ERR(0, 23, __pyx_L1_error)
    @@ -1753,63 +1778,69 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
     /* "clickhouse_driver/bufferedreader.pyx":25
      *         raise NotImplementedError
      * 
    - *     def read(self, Py_ssize_t unread):             # <<<<<<<<<<<<<<
    + *     def read(self, unsigned long long unread):             # <<<<<<<<<<<<<<
      *         # When the buffer is large enough bytes read are almost
      *         # always hit the buffer.
      */
     
     /* Python wrapper */
     static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_arg_unread); /*proto*/
     static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_5read(PyObject *__pyx_v_self, PyObject *__pyx_arg_unread) {
    -  Py_ssize_t __pyx_v_unread;
    +  unsigned PY_LONG_LONG __pyx_v_unread;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("read (wrapper)", 0);
       assert(__pyx_arg_unread); {
    -    __pyx_v_unread = __Pyx_PyIndex_AsSsize_t(__pyx_arg_unread); if (unlikely((__pyx_v_unread == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L3_error)
    +    __pyx_v_unread = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_arg_unread); if (unlikely((__pyx_v_unread == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 25, __pyx_L3_error)
       }
       goto __pyx_L4_argument_unpacking_done;
       __pyx_L3_error:;
       __Pyx_AddTraceback("clickhouse_driver.bufferedreader.BufferedReader.read", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __Pyx_RefNannyFinishContext();
       return NULL;
       __pyx_L4_argument_unpacking_done:;
    -  __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((Py_ssize_t)__pyx_v_unread));
    +  __pyx_r = __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(((struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *)__pyx_v_self), ((unsigned PY_LONG_LONG)__pyx_v_unread));
     
       /* function exit code */
       __Pyx_RefNannyFinishContext();
       return __pyx_r;
     }
     
    -static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_unread) {
    -  Py_ssize_t __pyx_v_next_position;
    -  Py_ssize_t __pyx_v_t;
    +static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_4read(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_unread) {
    +  unsigned PY_LONG_LONG __pyx_v_next_position;
    +  unsigned PY_LONG_LONG __pyx_v_t;
       char *__pyx_v_buffer_ptr;
    -  Py_ssize_t __pyx_v_read_bytes;
    +  unsigned PY_LONG_LONG __pyx_v_read_bytes;
       PyObject *__pyx_v_rv = NULL;
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       int __pyx_t_1;
    -  Py_ssize_t __pyx_t_2;
    +  unsigned PY_LONG_LONG __pyx_t_2;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
    -  Py_ssize_t __pyx_t_6;
    -  Py_ssize_t __pyx_t_7;
    +  unsigned PY_LONG_LONG __pyx_t_6;
    +  unsigned PY_LONG_LONG __pyx_t_7;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":28
      *         # When the buffer is large enough bytes read are almost
      *         # always hit the buffer.
    - *         cdef Py_ssize_t next_position = unread + self.position             # <<<<<<<<<<<<<<
    + *         cdef unsigned long long next_position = unread + self.position             # <<<<<<<<<<<<<<
      *         if next_position < self.current_buffer_size:
      *             t = self.position
      */
       __pyx_v_next_position = (__pyx_v_unread + __pyx_v_self->position);
     
       /* "clickhouse_driver/bufferedreader.pyx":29
      *         # always hit the buffer.
    - *         cdef Py_ssize_t next_position = unread + self.position
    + *         cdef unsigned long long next_position = unread + self.position
      *         if next_position < self.current_buffer_size:             # <<<<<<<<<<<<<<
      *             t = self.position
      *             self.position = next_position
    @@ -1818,7 +1849,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       if (__pyx_t_1) {
     
         /* "clickhouse_driver/bufferedreader.pyx":30
    - *         cdef Py_ssize_t next_position = unread + self.position
    + *         cdef unsigned long long next_position = unread + self.position
      *         if next_position < self.current_buffer_size:
      *             t = self.position             # <<<<<<<<<<<<<<
      *             self.position = next_position
    @@ -1859,7 +1890,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
     
         /* "clickhouse_driver/bufferedreader.pyx":29
      *         # always hit the buffer.
    - *         cdef Py_ssize_t next_position = unread + self.position
    + *         cdef unsigned long long next_position = unread + self.position
      *         if next_position < self.current_buffer_size:             # <<<<<<<<<<<<<<
      *             t = self.position
      *             self.position = next_position
    @@ -1870,7 +1901,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
      *             return bytes(self.buffer[t:self.position])
      * 
      *         cdef char* buffer_ptr = PyByteArray_AsString(self.buffer)             # <<<<<<<<<<<<<<
    - *         cdef Py_ssize_t read_bytes
    + *         cdef unsigned long long read_bytes
      *         rv = bytes()
      */
       __pyx_t_4 = __pyx_v_self->buffer;
    @@ -1880,7 +1911,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
     
       /* "clickhouse_driver/bufferedreader.pyx":36
      *         cdef char* buffer_ptr = PyByteArray_AsString(self.buffer)
    - *         cdef Py_ssize_t read_bytes
    + *         cdef unsigned long long read_bytes
      *         rv = bytes()             # <<<<<<<<<<<<<<
      * 
      *         while unread > 0:
    @@ -2032,7 +2063,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       /* "clickhouse_driver/bufferedreader.pyx":25
      *         raise NotImplementedError
      * 
    - *     def read(self, Py_ssize_t unread):             # <<<<<<<<<<<<<<
    + *     def read(self, unsigned long long unread):             # <<<<<<<<<<<<<<
      *         # When the buffer is large enough bytes read are almost
      *         # always hit the buffer.
      */
    @@ -2081,6 +2112,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
       int __pyx_t_5;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_one", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":54
    @@ -2144,7 +2178,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
      *         self.position += 1
      *         return rv
      */
    -  __pyx_t_5 = __Pyx_GetItemInt_ByteArray(__pyx_v_self->buffer, __pyx_v_self->position, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 58, __pyx_L1_error)
    +  __pyx_t_5 = __Pyx_GetItemInt_ByteArray(__pyx_v_self->buffer, __pyx_v_self->position, unsigned PY_LONG_LONG, 0, __Pyx_PyInt_From_unsigned_PY_LONG_LONG, 0, 0, 1); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 58, __pyx_L1_error)
       __pyx_v_rv = __pyx_t_5;
     
       /* "clickhouse_driver/bufferedreader.pyx":59
    @@ -2161,7 +2195,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
      *         self.position += 1
      *         return rv             # <<<<<<<<<<<<<<
      * 
    - *     def read_strings(self, Py_ssize_t n_items, encoding=None):
    + *     def read_strings(self, unsigned long long n_items, encoding=None):
      */
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_2 = __Pyx_PyInt_From_unsigned_char(__pyx_v_rv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
    @@ -2194,7 +2228,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
     /* "clickhouse_driver/bufferedreader.pyx":62
      *         return rv
      * 
    - *     def read_strings(self, Py_ssize_t n_items, encoding=None):             # <<<<<<<<<<<<<<
    + *     def read_strings(self, unsigned long long n_items, encoding=None):             # <<<<<<<<<<<<<<
      *         """
      *         Python has great overhead between function calls.
      */
    @@ -2203,8 +2237,11 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
     static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_9read_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
     static char __pyx_doc_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings[] = "\n        Python has great overhead between function calls.\n        We inline strings reading logic here to avoid this overhead.\n        ";
     static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_9read_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
    -  Py_ssize_t __pyx_v_n_items;
    +  unsigned PY_LONG_LONG __pyx_v_n_items;
       PyObject *__pyx_v_encoding = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("read_strings (wrapper)", 0);
    @@ -2247,7 +2284,7 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_
             default: goto __pyx_L5_argtuple_error;
           }
         }
    -    __pyx_v_n_items = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_n_items == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 62, __pyx_L3_error)
    +    __pyx_v_n_items = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[0]); if (unlikely((__pyx_v_n_items == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 62, __pyx_L3_error)
         __pyx_v_encoding = values[1];
       }
       goto __pyx_L4_argument_unpacking_done;
    @@ -2265,17 +2302,17 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_
       return __pyx_r;
     }
     
    -static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, Py_ssize_t __pyx_v_n_items, PyObject *__pyx_v_encoding) {
    +static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8read_strings(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_n_items, PyObject *__pyx_v_encoding) {
       PyObject *__pyx_v_items = NULL;
    -  Py_ssize_t __pyx_v_i;
    +  unsigned PY_LONG_LONG __pyx_v_i;
       char *__pyx_v_buffer_ptr;
    -  Py_ssize_t __pyx_v_right;
    -  Py_ssize_t __pyx_v_size;
    -  Py_ssize_t __pyx_v_shift;
    -  Py_ssize_t __pyx_v_bytes_read;
    -  unsigned char __pyx_v_b;
    +  unsigned PY_LONG_LONG __pyx_v_right;
    +  unsigned PY_LONG_LONG __pyx_v_size;
    +  unsigned PY_LONG_LONG __pyx_v_shift;
    +  unsigned PY_LONG_LONG __pyx_v_bytes_read;
    +  unsigned PY_LONG_LONG __pyx_v_b;
       char *__pyx_v_c_string;
    -  Py_ssize_t __pyx_v_c_string_size;
    +  unsigned PY_LONG_LONG __pyx_v_c_string_size;
       char *__pyx_v_c_encoding;
       PyObject *__pyx_v_rv = 0;
       PyObject *__pyx_r = NULL;
    @@ -2285,17 +2322,20 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
       char *__pyx_t_5;
    -  Py_ssize_t __pyx_t_6;
    -  Py_ssize_t __pyx_t_7;
    -  Py_ssize_t __pyx_t_8;
    -  Py_ssize_t __pyx_t_9;
    -  Py_ssize_t __pyx_t_10;
    -  Py_ssize_t __pyx_t_11;
    +  unsigned PY_LONG_LONG __pyx_t_6;
    +  unsigned PY_LONG_LONG __pyx_t_7;
    +  unsigned PY_LONG_LONG __pyx_t_8;
    +  unsigned PY_LONG_LONG __pyx_t_9;
    +  unsigned PY_LONG_LONG __pyx_t_10;
    +  unsigned PY_LONG_LONG __pyx_t_11;
       PyObject *__pyx_t_12 = NULL;
       PyObject *__pyx_t_13 = NULL;
       PyObject *__pyx_t_14 = NULL;
       int __pyx_t_15;
       PyObject *__pyx_t_16 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_strings", 0);
       __Pyx_INCREF(__pyx_v_encoding);
     
    @@ -2304,18 +2344,18 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
      *         """
      *         items = PyTuple_New(n_items)             # <<<<<<<<<<<<<<
      * 
    - *         cdef Py_ssize_t i
    + *         cdef unsigned long long i
      */
       __pyx_t_1 = PyTuple_New(__pyx_v_n_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_v_items = ((PyObject*)__pyx_t_1);
       __pyx_t_1 = 0;
     
       /* "clickhouse_driver/bufferedreader.pyx":71
    - *         cdef Py_ssize_t i
    + *         cdef unsigned long long i
      *         # Buffer vars
      *         cdef char* buffer_ptr = PyByteArray_AsString(self.buffer)             # <<<<<<<<<<<<<<
    - *         cdef Py_ssize_t right
    + *         cdef unsigned long long right
      *         # String length vars
      */
       __pyx_t_1 = __pyx_v_self->buffer;
    @@ -2327,31 +2367,31 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
      * 
      *         # String for decode vars.
      *         cdef char *c_string = NULL             # <<<<<<<<<<<<<<
    - *         cdef Py_ssize_t c_string_size = 1024
    + *         cdef unsigned long long c_string_size = 1024
      *         cdef char *c_encoding = NULL
      */
       __pyx_v_c_string = NULL;
     
       /* "clickhouse_driver/bufferedreader.pyx":79
      *         # String for decode vars.
      *         cdef char *c_string = NULL
    - *         cdef Py_ssize_t c_string_size = 1024             # <<<<<<<<<<<<<<
    + *         cdef unsigned long long c_string_size = 1024             # <<<<<<<<<<<<<<
      *         cdef char *c_encoding = NULL
      *         if encoding:
      */
       __pyx_v_c_string_size = 0x400;
     
       /* "clickhouse_driver/bufferedreader.pyx":80
      *         cdef char *c_string = NULL
    - *         cdef Py_ssize_t c_string_size = 1024
    + *         cdef unsigned long long c_string_size = 1024
      *         cdef char *c_encoding = NULL             # <<<<<<<<<<<<<<
      *         if encoding:
      *             encoding = encoding.encode('utf-8')
      */
       __pyx_v_c_encoding = NULL;
     
       /* "clickhouse_driver/bufferedreader.pyx":81
    - *         cdef Py_ssize_t c_string_size = 1024
    + *         cdef unsigned long long c_string_size = 1024
      *         cdef char *c_encoding = NULL
      *         if encoding:             # <<<<<<<<<<<<<<
      *             encoding = encoding.encode('utf-8')
    @@ -2379,7 +2419,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
             __Pyx_DECREF_SET(__pyx_t_3, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_u_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_u_utf_8);
    +    __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_kp_s_utf_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_kp_s_utf_8);
         __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    @@ -2398,7 +2438,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
         __pyx_v_c_encoding = __pyx_t_5;
     
         /* "clickhouse_driver/bufferedreader.pyx":81
    - *         cdef Py_ssize_t c_string_size = 1024
    + *         cdef unsigned long long c_string_size = 1024
      *         cdef char *c_encoding = NULL
      *         if encoding:             # <<<<<<<<<<<<<<
      *             encoding = encoding.encode('utf-8')
    @@ -3200,7 +3240,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       /* "clickhouse_driver/bufferedreader.pyx":62
      *         return rv
      * 
    - *     def read_strings(self, Py_ssize_t n_items, encoding=None):             # <<<<<<<<<<<<<<
    + *     def read_strings(self, unsigned long long n_items, encoding=None):             # <<<<<<<<<<<<<<
      *         """
      *         Python has great overhead between function calls.
      */
    @@ -3225,7 +3265,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
     /* "clickhouse_driver/bufferedreader.pyx":11
      * 
      * cdef class BufferedReader(object):
    - *     cdef public Py_ssize_t position, current_buffer_size             # <<<<<<<<<<<<<<
    + *     cdef public unsigned long long position, current_buffer_size             # <<<<<<<<<<<<<<
      *     cdef public bytearray buffer
      * 
      */
    @@ -3247,9 +3287,12 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__get__", 0);
       __Pyx_XDECREF(__pyx_r);
    -  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->position); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->position); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_r = __pyx_t_1;
       __pyx_t_1 = 0;
    @@ -3282,9 +3325,12 @@ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_8posit
     static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_8position_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value) {
       int __pyx_r;
       __Pyx_RefNannyDeclarations
    -  Py_ssize_t __pyx_t_1;
    +  unsigned PY_LONG_LONG __pyx_t_1;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__set__", 0);
    -  __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_value); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L1_error)
       __pyx_v_self->position = __pyx_t_1;
     
       /* function exit code */
    @@ -3315,9 +3361,12 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__get__", 0);
       __Pyx_XDECREF(__pyx_r);
    -  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
       __pyx_r = __pyx_t_1;
       __pyx_t_1 = 0;
    @@ -3350,9 +3399,12 @@ static int __pyx_pw_17clickhouse_driver_14bufferedreader_14BufferedReader_19curr
     static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19current_buffer_size_2__set__(struct __pyx_obj_17clickhouse_driver_14bufferedreader_BufferedReader *__pyx_v_self, PyObject *__pyx_v_value) {
       int __pyx_r;
       __Pyx_RefNannyDeclarations
    -  Py_ssize_t __pyx_t_1;
    +  unsigned PY_LONG_LONG __pyx_t_1;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__set__", 0);
    -  __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_value); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_value); if (unlikely((__pyx_t_1 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L1_error)
       __pyx_v_self->current_buffer_size = __pyx_t_1;
     
       /* function exit code */
    @@ -3368,7 +3420,7 @@ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_19curr
     
     /* "clickhouse_driver/bufferedreader.pyx":12
      * cdef class BufferedReader(object):
    - *     cdef public Py_ssize_t position, current_buffer_size
    + *     cdef public unsigned long long position, current_buffer_size
      *     cdef public bytearray buffer             # <<<<<<<<<<<<<<
      * 
      *     def __init__(self, bufsize):
    @@ -3420,6 +3472,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_6buffe
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__set__", 0);
       if (!(likely(PyByteArray_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 12, __pyx_L1_error)
       __pyx_t_1 = __pyx_v_value;
    @@ -3501,6 +3556,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       PyObject *__pyx_t_3 = NULL;
       int __pyx_t_4;
       int __pyx_t_5;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__reduce_cython__", 0);
     
       /* "(tree fragment)":5
    @@ -3510,9 +3568,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
      *     _dict = getattr(self, '__dict__', None)
      *     if _dict is not None:
      */
    -  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
       __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
    @@ -3736,6 +3794,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_14BufferedReader_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__setstate_cython__", 0);
     
       /* "(tree fragment)":17
    @@ -3781,6 +3842,9 @@ static int __pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_
     static int __pyx_pw_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_sock = 0;
       PyObject *__pyx_v_bufsize = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -3843,6 +3907,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketReader_
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":184
    @@ -3945,8 +4012,11 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketR
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    -  Py_ssize_t __pyx_t_4;
    +  unsigned PY_LONG_LONG __pyx_t_4;
       int __pyx_t_5;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_into_buffer", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":188
    @@ -3973,7 +4043,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketR
       if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 188, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    -  __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 188, __pyx_L1_error)
    +  __pyx_t_4 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_4 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 188, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v_self->__pyx_base.current_buffer_size = __pyx_t_4;
     
    @@ -4063,6 +4133,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketR
       int __pyx_t_4;
       int __pyx_t_5;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__reduce_cython__", 0);
     
       /* "(tree fragment)":5
    @@ -4072,9 +4145,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketR
      *     _dict = getattr(self, '__dict__', None)
      *     if _dict is not None:
      */
    -  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
       __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
    @@ -4311,6 +4384,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_20BufferedSocketR
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__setstate_cython__", 0);
     
       /* "(tree fragment)":17
    @@ -4356,6 +4432,9 @@ static int __pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedRea
     static int __pyx_pw_17clickhouse_driver_14bufferedreader_24CompressedBufferedReader_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_read_block = 0;
       PyObject *__pyx_v_bufsize = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -4418,6 +4497,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBufferedRea
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":198
    @@ -4522,6 +4604,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBuffe
       PyObject *__pyx_t_3 = NULL;
       Py_ssize_t __pyx_t_4;
       int __pyx_t_5;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_into_buffer", 0);
     
       /* "clickhouse_driver/bufferedreader.pyx":202
    @@ -4655,6 +4740,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBuffe
       int __pyx_t_4;
       int __pyx_t_5;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__reduce_cython__", 0);
     
       /* "(tree fragment)":5
    @@ -4664,9 +4752,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBuffe
      *     _dict = getattr(self, '__dict__', None)
      *     if _dict is not None:
      */
    -  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.current_buffer_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
       __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
    @@ -4903,6 +4991,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_24CompressedBuffe
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__setstate_cython__", 0);
     
       /* "(tree fragment)":17
    @@ -4948,6 +5039,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_1__pyx_unpickle_B
       PyObject *__pyx_v___pyx_type = 0;
       long __pyx_v___pyx_checksum;
       PyObject *__pyx_v___pyx_state = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedReader (wrapper)", 0);
    @@ -5025,6 +5119,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader___pyx_unpickle_Bu
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedReader", 0);
     
       /* "(tree fragment)":4
    @@ -5049,7 +5146,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader___pyx_unpickle_Bu
         __Pyx_INCREF(__pyx_n_s_PickleError);
         __Pyx_GIVEREF(__pyx_n_s_PickleError);
         PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
    -    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    +    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
         __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    @@ -5206,13 +5303,17 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    -  Py_ssize_t __pyx_t_2;
    +  unsigned PY_LONG_LONG __pyx_t_2;
       int __pyx_t_3;
    -  int __pyx_t_4;
    +  Py_ssize_t __pyx_t_4;
       int __pyx_t_5;
    -  PyObject *__pyx_t_6 = NULL;
    +  int __pyx_t_6;
       PyObject *__pyx_t_7 = NULL;
       PyObject *__pyx_t_8 = NULL;
    +  PyObject *__pyx_t_9 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedReader__set_state", 0);
     
       /* "(tree fragment)":12
    @@ -5240,7 +5341,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->current_buffer_size = __pyx_t_2;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -5249,7 +5350,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->position = __pyx_t_2;
     
    @@ -5263,16 +5364,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
         PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
         __PYX_ERR(1, 13, __pyx_L1_error)
       }
    -  __pyx_t_2 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_4 = ((__pyx_t_2 > 3) != 0);
    -  if (__pyx_t_4) {
    +  __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_5 = ((__pyx_t_4 > 3) != 0);
    +  if (__pyx_t_5) {
       } else {
    -    __pyx_t_3 = __pyx_t_4;
    +    __pyx_t_3 = __pyx_t_5;
         goto __pyx_L4_bool_binop_done;
       }
    -  __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_5 = (__pyx_t_4 != 0);
    -  __pyx_t_3 = __pyx_t_5;
    +  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_6 = (__pyx_t_5 != 0);
    +  __pyx_t_3 = __pyx_t_6;
       __pyx_L4_bool_binop_done:;
       if (__pyx_t_3) {
     
    @@ -5281,33 +5382,33 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
      *     if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'):
      *         __pyx_result.__dict__.update(__pyx_state[3])             # <<<<<<<<<<<<<<
      */
    -    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_6);
    -    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_7);
    -    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    +    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_8);
    +    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         if (unlikely(__pyx_v___pyx_state == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
           __PYX_ERR(1, 14, __pyx_L1_error)
         }
    -    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_6);
    -    __pyx_t_8 = NULL;
    -    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    -      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    -      if (likely(__pyx_t_8)) {
    -        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
    -        __Pyx_INCREF(__pyx_t_8);
    +    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_7);
    +    __pyx_t_9 = NULL;
    +    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    +      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    +      if (likely(__pyx_t_9)) {
    +        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    +        __Pyx_INCREF(__pyx_t_9);
             __Pyx_INCREF(function);
    -        __Pyx_DECREF_SET(__pyx_t_7, function);
    +        __Pyx_DECREF_SET(__pyx_t_8, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    -    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    -    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    +    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    +    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    +    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
         /* "(tree fragment)":13
    @@ -5331,9 +5432,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       goto __pyx_L0;
       __pyx_L1_error:;
       __Pyx_XDECREF(__pyx_t_1);
    -  __Pyx_XDECREF(__pyx_t_6);
       __Pyx_XDECREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_t_8);
    +  __Pyx_XDECREF(__pyx_t_9);
       __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedReader__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __pyx_r = 0;
       __pyx_L0:;
    @@ -5355,6 +5456,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_3__pyx_unpickle_B
       PyObject *__pyx_v___pyx_type = 0;
       long __pyx_v___pyx_checksum;
       PyObject *__pyx_v___pyx_state = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketReader (wrapper)", 0);
    @@ -5432,6 +5536,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_2__pyx_unpickle_B
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketReader", 0);
     
       /* "(tree fragment)":4
    @@ -5456,7 +5563,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_2__pyx_unpickle_B
         __Pyx_INCREF(__pyx_n_s_PickleError);
         __Pyx_GIVEREF(__pyx_n_s_PickleError);
         PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
    -    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    +    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
         __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    @@ -5613,13 +5720,17 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    -  Py_ssize_t __pyx_t_2;
    +  unsigned PY_LONG_LONG __pyx_t_2;
       int __pyx_t_3;
    -  int __pyx_t_4;
    +  Py_ssize_t __pyx_t_4;
       int __pyx_t_5;
    -  PyObject *__pyx_t_6 = NULL;
    +  int __pyx_t_6;
       PyObject *__pyx_t_7 = NULL;
       PyObject *__pyx_t_8 = NULL;
    +  PyObject *__pyx_t_9 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketReader__set_state", 0);
     
       /* "(tree fragment)":12
    @@ -5647,7 +5758,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.current_buffer_size = __pyx_t_2;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -5656,7 +5767,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.position = __pyx_t_2;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -5681,16 +5792,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
         PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
         __PYX_ERR(1, 13, __pyx_L1_error)
       }
    -  __pyx_t_2 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_4 = ((__pyx_t_2 > 4) != 0);
    -  if (__pyx_t_4) {
    +  __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_5 = ((__pyx_t_4 > 4) != 0);
    +  if (__pyx_t_5) {
       } else {
    -    __pyx_t_3 = __pyx_t_4;
    +    __pyx_t_3 = __pyx_t_5;
         goto __pyx_L4_bool_binop_done;
       }
    -  __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_5 = (__pyx_t_4 != 0);
    -  __pyx_t_3 = __pyx_t_5;
    +  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_6 = (__pyx_t_5 != 0);
    +  __pyx_t_3 = __pyx_t_6;
       __pyx_L4_bool_binop_done:;
       if (__pyx_t_3) {
     
    @@ -5699,33 +5810,33 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
      *     if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'):
      *         __pyx_result.__dict__.update(__pyx_state[4])             # <<<<<<<<<<<<<<
      */
    -    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_6);
    -    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_7);
    -    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    +    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_8);
    +    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         if (unlikely(__pyx_v___pyx_state == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
           __PYX_ERR(1, 14, __pyx_L1_error)
         }
    -    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_6);
    -    __pyx_t_8 = NULL;
    -    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    -      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    -      if (likely(__pyx_t_8)) {
    -        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
    -        __Pyx_INCREF(__pyx_t_8);
    +    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_7);
    +    __pyx_t_9 = NULL;
    +    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    +      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    +      if (likely(__pyx_t_9)) {
    +        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    +        __Pyx_INCREF(__pyx_t_9);
             __Pyx_INCREF(function);
    -        __Pyx_DECREF_SET(__pyx_t_7, function);
    +        __Pyx_DECREF_SET(__pyx_t_8, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    -    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    -    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    +    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    +    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    +    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
         /* "(tree fragment)":13
    @@ -5749,9 +5860,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Buf
       goto __pyx_L0;
       __pyx_L1_error:;
       __Pyx_XDECREF(__pyx_t_1);
    -  __Pyx_XDECREF(__pyx_t_6);
       __Pyx_XDECREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_t_8);
    +  __Pyx_XDECREF(__pyx_t_9);
       __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_BufferedSocketReader__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __pyx_r = 0;
       __pyx_L0:;
    @@ -5773,6 +5884,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedreader_5__pyx_unpickle_C
       PyObject *__pyx_v___pyx_type = 0;
       long __pyx_v___pyx_checksum;
       PyObject *__pyx_v___pyx_state = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedReader (wrapper)", 0);
    @@ -5850,6 +5964,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_4__pyx_unpickle_C
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedReader", 0);
     
       /* "(tree fragment)":4
    @@ -5874,7 +5991,7 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedreader_4__pyx_unpickle_C
         __Pyx_INCREF(__pyx_n_s_PickleError);
         __Pyx_GIVEREF(__pyx_n_s_PickleError);
         PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_PickleError);
    -    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    +    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_2, -1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_3);
         __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
         __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    @@ -6031,13 +6148,17 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Com
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    -  Py_ssize_t __pyx_t_2;
    +  unsigned PY_LONG_LONG __pyx_t_2;
       int __pyx_t_3;
    -  int __pyx_t_4;
    +  Py_ssize_t __pyx_t_4;
       int __pyx_t_5;
    -  PyObject *__pyx_t_6 = NULL;
    +  int __pyx_t_6;
       PyObject *__pyx_t_7 = NULL;
       PyObject *__pyx_t_8 = NULL;
    +  PyObject *__pyx_t_9 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedReader__set_state", 0);
     
       /* "(tree fragment)":12
    @@ -6065,7 +6186,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Com
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.current_buffer_size = __pyx_t_2;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -6074,7 +6195,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Com
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_2 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.position = __pyx_t_2;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -6099,16 +6220,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Com
         PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
         __PYX_ERR(1, 13, __pyx_L1_error)
       }
    -  __pyx_t_2 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_4 = ((__pyx_t_2 > 4) != 0);
    -  if (__pyx_t_4) {
    +  __pyx_t_4 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_5 = ((__pyx_t_4 > 4) != 0);
    +  if (__pyx_t_5) {
       } else {
    -    __pyx_t_3 = __pyx_t_4;
    +    __pyx_t_3 = __pyx_t_5;
         goto __pyx_L4_bool_binop_done;
       }
    -  __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_5 = (__pyx_t_4 != 0);
    -  __pyx_t_3 = __pyx_t_5;
    +  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_6 = (__pyx_t_5 != 0);
    +  __pyx_t_3 = __pyx_t_6;
       __pyx_L4_bool_binop_done:;
       if (__pyx_t_3) {
     
    @@ -6117,33 +6238,33 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Com
      *     if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'):
      *         __pyx_result.__dict__.update(__pyx_state[4])             # <<<<<<<<<<<<<<
      */
    -    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_6);
    -    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_update); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_7);
    -    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    +    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_8);
    +    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         if (unlikely(__pyx_v___pyx_state == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
           __PYX_ERR(1, 14, __pyx_L1_error)
         }
    -    __pyx_t_6 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_6);
    -    __pyx_t_8 = NULL;
    -    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
    -      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
    -      if (likely(__pyx_t_8)) {
    -        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
    -        __Pyx_INCREF(__pyx_t_8);
    +    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_7);
    +    __pyx_t_9 = NULL;
    +    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    +      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    +      if (likely(__pyx_t_9)) {
    +        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    +        __Pyx_INCREF(__pyx_t_9);
             __Pyx_INCREF(function);
    -        __Pyx_DECREF_SET(__pyx_t_7, function);
    +        __Pyx_DECREF_SET(__pyx_t_8, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    -    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    -    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    +    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    +    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    +    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
         /* "(tree fragment)":13
    @@ -6167,9 +6288,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedreader___pyx_unpickle_Com
       goto __pyx_L0;
       __pyx_L1_error:;
       __Pyx_XDECREF(__pyx_t_1);
    -  __Pyx_XDECREF(__pyx_t_6);
       __Pyx_XDECREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_t_8);
    +  __Pyx_XDECREF(__pyx_t_9);
       __Pyx_AddTraceback("clickhouse_driver.bufferedreader.__pyx_unpickle_CompressedBufferedReader__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __pyx_r = 0;
       __pyx_L0:;
    @@ -6628,7 +6749,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
       {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
       {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
       {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
    -  {&__pyx_kp_u_Unexpected_EOF_while_reading_byt, __pyx_k_Unexpected_EOF_while_reading_byt, sizeof(__pyx_k_Unexpected_EOF_while_reading_byt), 0, 1, 0, 0},
    +  {&__pyx_kp_s_Unexpected_EOF_while_reading_byt, __pyx_k_Unexpected_EOF_while_reading_byt, sizeof(__pyx_k_Unexpected_EOF_while_reading_byt), 0, 0, 1, 0},
       {&__pyx_n_s_UnicodeDecodeError, __pyx_k_UnicodeDecodeError, sizeof(__pyx_k_UnicodeDecodeError), 0, 0, 1, 1},
       {&__pyx_n_s_bufsize, __pyx_k_bufsize, sizeof(__pyx_k_bufsize), 0, 0, 1, 1},
       {&__pyx_n_s_clickhouse_driver_bufferedreader, __pyx_k_clickhouse_driver_bufferedreader, sizeof(__pyx_k_clickhouse_driver_bufferedreader), 0, 0, 1, 1},
    @@ -6667,7 +6788,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = {
       {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1},
       {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
       {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
    -  {&__pyx_kp_u_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 1, 0, 0},
    +  {&__pyx_kp_s_utf_8, __pyx_k_utf_8, sizeof(__pyx_k_utf_8), 0, 0, 1, 0},
       {0, 0, 0, 0, 0, 0, 0}
     };
     static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
    @@ -6694,7 +6815,7 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
      * 
      * 
      */
    -  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Unexpected_EOF_while_reading_byt); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 191, __pyx_L1_error)
    +  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Unexpected_EOF_while_reading_byt); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 191, __pyx
    ... [truncated]
    
  • clickhouse_driver/bufferedreader.pyx+10 10 modified
    @@ -8,7 +8,7 @@ from libc.string cimport memcpy
     
     
     cdef class BufferedReader(object):
    -    cdef public Py_ssize_t position, current_buffer_size
    +    cdef public unsigned long long position, current_buffer_size
         cdef public bytearray buffer
     
         def __init__(self, bufsize):
    @@ -22,17 +22,17 @@ cdef class BufferedReader(object):
         def read_into_buffer(self):
             raise NotImplementedError
     
    -    def read(self, Py_ssize_t unread):
    +    def read(self, unsigned long long unread):
             # When the buffer is large enough bytes read are almost
             # always hit the buffer.
    -        cdef Py_ssize_t next_position = unread + self.position
    +        cdef unsigned long long next_position = unread + self.position
             if next_position < self.current_buffer_size:
                 t = self.position
                 self.position = next_position
                 return bytes(self.buffer[t:self.position])
     
             cdef char* buffer_ptr = PyByteArray_AsString(self.buffer)
    -        cdef Py_ssize_t read_bytes
    +        cdef unsigned long long read_bytes
             rv = bytes()
     
             while unread > 0:
    @@ -59,24 +59,24 @@ cdef class BufferedReader(object):
             self.position += 1
             return rv
     
    -    def read_strings(self, Py_ssize_t n_items, encoding=None):
    +    def read_strings(self, unsigned long long n_items, encoding=None):
             """
             Python has great overhead between function calls.
             We inline strings reading logic here to avoid this overhead.
             """
             items = PyTuple_New(n_items)
     
    -        cdef Py_ssize_t i
    +        cdef unsigned long long i
             # Buffer vars
             cdef char* buffer_ptr = PyByteArray_AsString(self.buffer)
    -        cdef Py_ssize_t right
    +        cdef unsigned long long right
             # String length vars
    -        cdef Py_ssize_t size, shift, bytes_read
    -        cdef unsigned char b
    +        cdef unsigned long long size, shift, bytes_read
    +        cdef unsigned long long b
     
             # String for decode vars.
             cdef char *c_string = NULL
    -        cdef Py_ssize_t c_string_size = 1024
    +        cdef unsigned long long c_string_size = 1024
             cdef char *c_encoding = NULL
             if encoding:
                 encoding = encoding.encode('utf-8')
    
  • clickhouse_driver/bufferedwriter.c+503 153 modified
    @@ -1,4 +1,4 @@
    -/* Generated by Cython 0.29.17 */
    +/* Generated by Cython 0.29.21 */
     
     /* BEGIN: Cython Metadata
     {
    @@ -20,8 +20,8 @@ END: Cython Metadata */
     #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
         #error Cython requires Python 2.6+ or Python 3.3+.
     #else
    -#define CYTHON_ABI "0_29_17"
    -#define CYTHON_HEX_VERSION 0x001D11F0
    +#define CYTHON_ABI "0_29_21"
    +#define CYTHON_HEX_VERSION 0x001D15F0
     #define CYTHON_FUTURE_DIVISION 1
     #include <stddef.h>
     #ifndef offsetof
    @@ -448,7 +448,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
       #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
       #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
    +  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
       #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    +  #else
    +  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
    +  #endif
     #else
       #define CYTHON_PEP393_ENABLED 0
       #define PyUnicode_1BYTE_KIND  1
    @@ -511,6 +515,13 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
     #ifndef PySet_CheckExact
       #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
     #endif
    +#if PY_VERSION_HEX >= 0x030900A4
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
    +#else
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
    +#endif
     #if CYTHON_ASSUME_SAFE_MACROS
       #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
     #else
    @@ -550,7 +561,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
     #endif
     #if PY_MAJOR_VERSION >= 3
    -  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
    +  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
     #else
       #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
     #endif
    @@ -591,11 +602,10 @@ static CYTHON_INLINE float __PYX_NAN() {
     #define __Pyx_truncl truncl
     #endif
     
    -
    +#define __PYX_MARK_ERR_POS(f_index, lineno) \
    +    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
     #define __PYX_ERR(f_index, lineno, Ln_error) \
    -{ \
    -  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
    -}
    +    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
     
     #ifndef __PYX_EXTERN_C
       #ifdef __cplusplus
    @@ -836,14 +846,14 @@ struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter;
      * 
      * cdef class BufferedWriter(object):             # <<<<<<<<<<<<<<
      *     cdef char* buffer
    - *     cdef Py_ssize_t position, buffer_size
    + *     cdef unsigned long long position, buffer_size
      */
     struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter {
       PyObject_HEAD
       struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_vtab;
       char *buffer;
    -  Py_ssize_t position;
    -  Py_ssize_t buffer_size;
    +  unsigned PY_LONG_LONG position;
    +  unsigned PY_LONG_LONG buffer_size;
     };
     
     
    @@ -879,7 +889,7 @@ struct __pyx_obj_17clickhouse_driver_14bufferedwriter_CompressedBufferedWriter {
      * 
      * cdef class BufferedWriter(object):             # <<<<<<<<<<<<<<
      *     cdef char* buffer
    - *     cdef Py_ssize_t position, buffer_size
    + *     cdef unsigned long long position, buffer_size
      */
     
     struct __pyx_vtabstruct_17clickhouse_driver_14bufferedwriter_BufferedWriter {
    @@ -1254,9 +1264,15 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
     static void __Pyx_AddTraceback(const char *funcname, int c_line,
                                    int py_line, const char *filename);
     
    +/* CIntToPy.proto */
    +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value);
    +
     /* CIntToPy.proto */
     static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
     
    +/* CIntFromPy.proto */
    +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *);
    +
     /* CIntFromPy.proto */
     static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
     
    @@ -1486,7 +1502,7 @@ static PyObject *__pyx_n_s_varint;
     static PyObject *__pyx_n_s_write;
     static PyObject *__pyx_n_s_write_into_stream;
     static PyObject *__pyx_n_s_write_varint;
    -static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, Py_ssize_t __pyx_v_bufsize); /* proto */
    +static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_bufsize); /* proto */
     static void __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_2__dealloc__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_4write_into_stream(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self); /* proto */
     static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_6write(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_data); /* proto */
    @@ -1522,17 +1538,20 @@ static PyObject *__pyx_codeobj__7;
     /* Late includes */
     
     /* "clickhouse_driver/bufferedwriter.pyx":12
    - *     cdef Py_ssize_t position, buffer_size
    + *     cdef unsigned long long position, buffer_size
      * 
    - *     def __init__(self, Py_ssize_t bufsize):             # <<<<<<<<<<<<<<
    + *     def __init__(self, unsigned long long bufsize):             # <<<<<<<<<<<<<<
      *         self.buffer = <char *> PyMem_Malloc(bufsize)
      *         if not self.buffer:
      */
     
     /* Python wrapper */
     static int __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
     static int __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
    -  Py_ssize_t __pyx_v_bufsize;
    +  unsigned PY_LONG_LONG __pyx_v_bufsize;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -1562,7 +1581,7 @@ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__ini
         } else {
           values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
         }
    -    __pyx_v_bufsize = __Pyx_PyIndex_AsSsize_t(values[0]); if (unlikely((__pyx_v_bufsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 12, __pyx_L3_error)
    +    __pyx_v_bufsize = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(values[0]); if (unlikely((__pyx_v_bufsize == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 12, __pyx_L3_error)
       }
       goto __pyx_L4_argument_unpacking_done;
       __pyx_L5_argtuple_error:;
    @@ -1579,26 +1598,29 @@ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_1__ini
       return __pyx_r;
     }
     
    -static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, Py_ssize_t __pyx_v_bufsize) {
    +static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init__(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, unsigned PY_LONG_LONG __pyx_v_bufsize) {
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       int __pyx_t_1;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/bufferedwriter.pyx":13
      * 
    - *     def __init__(self, Py_ssize_t bufsize):
    + *     def __init__(self, unsigned long long bufsize):
      *         self.buffer = <char *> PyMem_Malloc(bufsize)             # <<<<<<<<<<<<<<
      *         if not self.buffer:
      *             raise MemoryError()
      */
       __pyx_v_self->buffer = ((char *)PyMem_Malloc(__pyx_v_bufsize));
     
       /* "clickhouse_driver/bufferedwriter.pyx":14
    - *     def __init__(self, Py_ssize_t bufsize):
    + *     def __init__(self, unsigned long long bufsize):
      *         self.buffer = <char *> PyMem_Malloc(bufsize)
      *         if not self.buffer:             # <<<<<<<<<<<<<<
      *             raise MemoryError()
    @@ -1617,7 +1639,7 @@ static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init
         PyErr_NoMemory(); __PYX_ERR(0, 15, __pyx_L1_error)
     
         /* "clickhouse_driver/bufferedwriter.pyx":14
    - *     def __init__(self, Py_ssize_t bufsize):
    + *     def __init__(self, unsigned long long bufsize):
      *         self.buffer = <char *> PyMem_Malloc(bufsize)
      *         if not self.buffer:             # <<<<<<<<<<<<<<
      *             raise MemoryError()
    @@ -1682,9 +1704,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter___init
       __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
     
       /* "clickhouse_driver/bufferedwriter.pyx":12
    - *     cdef Py_ssize_t position, buffer_size
    + *     cdef unsigned long long position, buffer_size
      * 
    - *     def __init__(self, Py_ssize_t bufsize):             # <<<<<<<<<<<<<<
    + *     def __init__(self, unsigned long long bufsize):             # <<<<<<<<<<<<<<
      *         self.buffer = <char *> PyMem_Malloc(bufsize)
      *         if not self.buffer:
      */
    @@ -1763,6 +1785,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_w
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_into_stream", 0);
       /* Check if called by wrapper */
       if (unlikely(__pyx_skip_dispatch)) ;
    @@ -1860,6 +1885,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_into_stream", 0);
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write_into_stream(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
    @@ -1883,15 +1911,15 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
      *         raise NotImplementedError
      * 
      *     cpdef write(self, data):             # <<<<<<<<<<<<<<
    - *         cdef Py_ssize_t written = 0
    - *         cdef Py_ssize_t to_write, size
    + *         cdef unsigned long long written = 0
    + *         cdef unsigned long long to_write, size
      */
     
     static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_7write(PyObject *__pyx_v_self, PyObject *__pyx_v_data); /*proto*/
     static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write(struct __pyx_obj_17clickhouse_driver_14bufferedwriter_BufferedWriter *__pyx_v_self, PyObject *__pyx_v_data, int __pyx_skip_dispatch) {
    -  Py_ssize_t __pyx_v_written;
    -  Py_ssize_t __pyx_v_size;
    -  Py_ssize_t __pyx_v_data_len;
    +  unsigned PY_LONG_LONG __pyx_v_written;
    +  unsigned PY_LONG_LONG __pyx_v_size;
    +  unsigned PY_LONG_LONG __pyx_v_data_len;
       char *__pyx_v_c_data;
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
    @@ -1902,8 +1930,12 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_w
       Py_ssize_t __pyx_t_5;
       char *__pyx_t_6;
       int __pyx_t_7;
    -  Py_ssize_t __pyx_t_8;
    -  Py_ssize_t __pyx_t_9;
    +  unsigned PY_LONG_LONG __pyx_t_8;
    +  unsigned PY_LONG_LONG __pyx_t_9;
    +  unsigned PY_LONG_LONG __pyx_t_10;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write", 0);
       /* Check if called by wrapper */
       if (unlikely(__pyx_skip_dispatch)) ;
    @@ -1955,16 +1987,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_w
       /* "clickhouse_driver/bufferedwriter.pyx":29
      * 
      *     cpdef write(self, data):
    - *         cdef Py_ssize_t written = 0             # <<<<<<<<<<<<<<
    - *         cdef Py_ssize_t to_write, size
    - *         cdef Py_ssize_t data_len = len(data)
    + *         cdef unsigned long long written = 0             # <<<<<<<<<<<<<<
    + *         cdef unsigned long long to_write, size
    + *         cdef unsigned long long data_len = len(data)
      */
       __pyx_v_written = 0;
     
       /* "clickhouse_driver/bufferedwriter.pyx":31
    - *         cdef Py_ssize_t written = 0
    - *         cdef Py_ssize_t to_write, size
    - *         cdef Py_ssize_t data_len = len(data)             # <<<<<<<<<<<<<<
    + *         cdef unsigned long long written = 0
    + *         cdef unsigned long long to_write, size
    + *         cdef unsigned long long data_len = len(data)             # <<<<<<<<<<<<<<
      *         cdef char* c_data
      * 
      */
    @@ -1999,14 +2031,14 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_w
      *             memcpy(&self.buffer[self.position], &c_data[written], size)
      * 
      */
    -    __pyx_t_5 = (__pyx_v_self->buffer_size - __pyx_v_self->position);
    -    __pyx_t_8 = (__pyx_v_data_len - __pyx_v_written);
    -    if (((__pyx_t_5 < __pyx_t_8) != 0)) {
    -      __pyx_t_9 = __pyx_t_5;
    +    __pyx_t_8 = (__pyx_v_self->buffer_size - __pyx_v_self->position);
    +    __pyx_t_9 = (__pyx_v_data_len - __pyx_v_written);
    +    if (((__pyx_t_8 < __pyx_t_9) != 0)) {
    +      __pyx_t_10 = __pyx_t_8;
         } else {
    -      __pyx_t_9 = __pyx_t_8;
    +      __pyx_t_10 = __pyx_t_9;
         }
    -    __pyx_v_size = __pyx_t_9;
    +    __pyx_v_size = __pyx_t_10;
     
         /* "clickhouse_driver/bufferedwriter.pyx":38
      *         while written < data_len:
    @@ -2070,8 +2102,8 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_w
      *         raise NotImplementedError
      * 
      *     cpdef write(self, data):             # <<<<<<<<<<<<<<
    - *         cdef Py_ssize_t written = 0
    - *         cdef Py_ssize_t to_write, size
    + *         cdef unsigned long long written = 0
    + *         cdef unsigned long long to_write, size
      */
     
       /* function exit code */
    @@ -2107,6 +2139,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write", 0);
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_14BufferedWriter_write(__pyx_v_self, __pyx_v_data, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 28, __pyx_L1_error)
    @@ -2151,6 +2186,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("flush", 0);
     
       /* "clickhouse_driver/bufferedwriter.pyx":47
    @@ -2198,6 +2236,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
     static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_11write_strings(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_items = 0;
       PyObject *__pyx_v_encoding = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("write_strings (wrapper)", 0);
    @@ -2274,6 +2315,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
       PyObject *__pyx_t_9 = NULL;
       int __pyx_t_10;
       PyObject *__pyx_t_11 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_strings", 0);
     
       /* "clickhouse_driver/bufferedwriter.pyx":50
    @@ -2557,6 +2601,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
       PyObject *__pyx_t_4 = NULL;
       int __pyx_t_5;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__reduce_cython__", 0);
     
       /* "(tree fragment)":5
    @@ -2568,9 +2615,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
      */
       __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
    -  __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_self->position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
       __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_4);
    @@ -2794,6 +2841,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_14BufferedWriter_
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__setstate_cython__", 0);
     
       /* "(tree fragment)":17
    @@ -2839,6 +2889,9 @@ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_
     static int __pyx_pw_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_sock = 0;
       PyObject *__pyx_v_bufsize = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -2901,6 +2954,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/bufferedwriter.pyx":67
    @@ -2992,6 +3048,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_20BufferedSocketWr
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_into_stream", 0);
       /* Check if called by wrapper */
       if (unlikely(__pyx_skip_dispatch)) ;
    @@ -3127,6 +3186,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketW
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_into_stream", 0);
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_20BufferedSocketWriter_write_into_stream(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error)
    @@ -3177,6 +3239,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketW
       PyObject *__pyx_t_4 = NULL;
       int __pyx_t_5;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__reduce_cython__", 0);
     
       /* "(tree fragment)":5
    @@ -3188,9 +3253,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketW
      */
       __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx_base.buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
    -  __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
       __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_4);
    @@ -3418,6 +3483,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_20BufferedSocketW
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__setstate_cython__", 0);
     
       /* "(tree fragment)":17
    @@ -3463,6 +3531,9 @@ static int __pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWri
     static int __pyx_pw_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_compressor = 0;
       PyObject *__pyx_v_bufsize = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       int __pyx_r;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -3525,6 +3596,9 @@ static int __pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWri
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/bufferedwriter.pyx":81
    @@ -3616,6 +3690,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter_24CompressedBuffer
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_into_stream", 0);
       /* Check if called by wrapper */
       if (unlikely(__pyx_skip_dispatch)) ;
    @@ -3751,6 +3828,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBuffe
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_into_stream", 0);
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_1 = __pyx_f_17clickhouse_driver_14bufferedwriter_24CompressedBufferedWriter_write_into_stream(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error)
    @@ -3794,6 +3874,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBuffe
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("flush", 0);
     
       /* "clickhouse_driver/bufferedwriter.pyx":91
    @@ -3856,6 +3939,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBuffe
       PyObject *__pyx_t_4 = NULL;
       int __pyx_t_5;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__reduce_cython__", 0);
     
       /* "(tree fragment)":5
    @@ -3867,9 +3953,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBuffe
      */
       __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->__pyx_base.buffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_2 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.buffer_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_2);
    -  __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_self->__pyx_base.position); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_3);
       __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 5, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_4);
    @@ -4097,6 +4183,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_24CompressedBuffe
       PyObject *__pyx_r = NULL;
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__setstate_cython__", 0);
     
       /* "(tree fragment)":17
    @@ -4142,6 +4231,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_1__pyx_unpickle_B
       PyObject *__pyx_v___pyx_type = 0;
       long __pyx_v___pyx_checksum;
       PyObject *__pyx_v___pyx_state = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedWriter (wrapper)", 0);
    @@ -4219,6 +4311,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Bu
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedWriter", 0);
     
       /* "(tree fragment)":4
    @@ -4401,13 +4496,17 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       char *__pyx_t_2;
    -  Py_ssize_t __pyx_t_3;
    +  unsigned PY_LONG_LONG __pyx_t_3;
       int __pyx_t_4;
    -  int __pyx_t_5;
    +  Py_ssize_t __pyx_t_5;
       int __pyx_t_6;
    -  PyObject *__pyx_t_7 = NULL;
    +  int __pyx_t_7;
       PyObject *__pyx_t_8 = NULL;
       PyObject *__pyx_t_9 = NULL;
    +  PyObject *__pyx_t_10 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedWriter__set_state", 0);
     
       /* "(tree fragment)":12
    @@ -4432,7 +4531,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->buffer_size = __pyx_t_3;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -4441,7 +4540,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->position = __pyx_t_3;
     
    @@ -4455,16 +4554,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
         PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
         __PYX_ERR(1, 13, __pyx_L1_error)
       }
    -  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_5 = ((__pyx_t_3 > 3) != 0);
    -  if (__pyx_t_5) {
    +  __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_6 = ((__pyx_t_5 > 3) != 0);
    +  if (__pyx_t_6) {
       } else {
    -    __pyx_t_4 = __pyx_t_5;
    +    __pyx_t_4 = __pyx_t_6;
         goto __pyx_L4_bool_binop_done;
       }
    -  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_6 = (__pyx_t_5 != 0);
    -  __pyx_t_4 = __pyx_t_6;
    +  __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_7 = (__pyx_t_6 != 0);
    +  __pyx_t_4 = __pyx_t_7;
       __pyx_L4_bool_binop_done:;
       if (__pyx_t_4) {
     
    @@ -4473,33 +4572,33 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
      *     if len(__pyx_state) > 3 and hasattr(__pyx_result, '__dict__'):
      *         __pyx_result.__dict__.update(__pyx_state[3])             # <<<<<<<<<<<<<<
      */
    -    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_7);
    -    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_8);
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_9);
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (unlikely(__pyx_v___pyx_state == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
           __PYX_ERR(1, 14, __pyx_L1_error)
         }
    -    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_7);
    -    __pyx_t_9 = NULL;
    -    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    -      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    -      if (likely(__pyx_t_9)) {
    -        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    -        __Pyx_INCREF(__pyx_t_9);
    +    __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_8);
    +    __pyx_t_10 = NULL;
    +    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
    +      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
    +      if (likely(__pyx_t_10)) {
    +        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
    +        __Pyx_INCREF(__pyx_t_10);
             __Pyx_INCREF(function);
    -        __Pyx_DECREF_SET(__pyx_t_8, function);
    +        __Pyx_DECREF_SET(__pyx_t_9, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    -    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
    +    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    -    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    +    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
         /* "(tree fragment)":13
    @@ -4523,9 +4622,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       goto __pyx_L0;
       __pyx_L1_error:;
       __Pyx_XDECREF(__pyx_t_1);
    -  __Pyx_XDECREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_t_8);
       __Pyx_XDECREF(__pyx_t_9);
    +  __Pyx_XDECREF(__pyx_t_10);
       __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedWriter__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __pyx_r = 0;
       __pyx_L0:;
    @@ -4547,6 +4646,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_3__pyx_unpickle_B
       PyObject *__pyx_v___pyx_type = 0;
       long __pyx_v___pyx_checksum;
       PyObject *__pyx_v___pyx_state = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketWriter (wrapper)", 0);
    @@ -4624,6 +4726,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_2__pyx_unpickle_B
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketWriter", 0);
     
       /* "(tree fragment)":4
    @@ -4806,13 +4911,17 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       char *__pyx_t_2;
    -  Py_ssize_t __pyx_t_3;
    +  unsigned PY_LONG_LONG __pyx_t_3;
       int __pyx_t_4;
    -  int __pyx_t_5;
    +  Py_ssize_t __pyx_t_5;
       int __pyx_t_6;
    -  PyObject *__pyx_t_7 = NULL;
    +  int __pyx_t_7;
       PyObject *__pyx_t_8 = NULL;
       PyObject *__pyx_t_9 = NULL;
    +  PyObject *__pyx_t_10 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_BufferedSocketWriter__set_state", 0);
     
       /* "(tree fragment)":12
    @@ -4837,7 +4946,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.buffer_size = __pyx_t_3;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -4846,7 +4955,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.position = __pyx_t_3;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -4871,16 +4980,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
         PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
         __PYX_ERR(1, 13, __pyx_L1_error)
       }
    -  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_5 = ((__pyx_t_3 > 4) != 0);
    -  if (__pyx_t_5) {
    +  __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_6 = ((__pyx_t_5 > 4) != 0);
    +  if (__pyx_t_6) {
       } else {
    -    __pyx_t_4 = __pyx_t_5;
    +    __pyx_t_4 = __pyx_t_6;
         goto __pyx_L4_bool_binop_done;
       }
    -  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_6 = (__pyx_t_5 != 0);
    -  __pyx_t_4 = __pyx_t_6;
    +  __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_7 = (__pyx_t_6 != 0);
    +  __pyx_t_4 = __pyx_t_7;
       __pyx_L4_bool_binop_done:;
       if (__pyx_t_4) {
     
    @@ -4889,33 +4998,33 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
      *     if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'):
      *         __pyx_result.__dict__.update(__pyx_state[4])             # <<<<<<<<<<<<<<
      */
    -    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_7);
    -    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_8);
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_9);
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (unlikely(__pyx_v___pyx_state == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
           __PYX_ERR(1, 14, __pyx_L1_error)
         }
    -    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_7);
    -    __pyx_t_9 = NULL;
    -    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    -      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    -      if (likely(__pyx_t_9)) {
    -        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    -        __Pyx_INCREF(__pyx_t_9);
    +    __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_8);
    +    __pyx_t_10 = NULL;
    +    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
    +      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
    +      if (likely(__pyx_t_10)) {
    +        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
    +        __Pyx_INCREF(__pyx_t_10);
             __Pyx_INCREF(function);
    -        __Pyx_DECREF_SET(__pyx_t_8, function);
    +        __Pyx_DECREF_SET(__pyx_t_9, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    -    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
    +    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    -    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    +    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
         /* "(tree fragment)":13
    @@ -4939,9 +5048,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Buf
       goto __pyx_L0;
       __pyx_L1_error:;
       __Pyx_XDECREF(__pyx_t_1);
    -  __Pyx_XDECREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_t_8);
       __Pyx_XDECREF(__pyx_t_9);
    +  __Pyx_XDECREF(__pyx_t_10);
       __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_BufferedSocketWriter__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __pyx_r = 0;
       __pyx_L0:;
    @@ -4963,6 +5072,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_14bufferedwriter_5__pyx_unpickle_C
       PyObject *__pyx_v___pyx_type = 0;
       long __pyx_v___pyx_checksum;
       PyObject *__pyx_v___pyx_state = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedWriter (wrapper)", 0);
    @@ -5040,6 +5152,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_14bufferedwriter_4__pyx_unpickle_C
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
       int __pyx_t_6;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedWriter", 0);
     
       /* "(tree fragment)":4
    @@ -5222,13 +5337,17 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Com
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       char *__pyx_t_2;
    -  Py_ssize_t __pyx_t_3;
    +  unsigned PY_LONG_LONG __pyx_t_3;
       int __pyx_t_4;
    -  int __pyx_t_5;
    +  Py_ssize_t __pyx_t_5;
       int __pyx_t_6;
    -  PyObject *__pyx_t_7 = NULL;
    +  int __pyx_t_7;
       PyObject *__pyx_t_8 = NULL;
       PyObject *__pyx_t_9 = NULL;
    +  PyObject *__pyx_t_10 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__pyx_unpickle_CompressedBufferedWriter__set_state", 0);
     
       /* "(tree fragment)":12
    @@ -5253,7 +5372,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Com
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.buffer_size = __pyx_t_3;
       if (unlikely(__pyx_v___pyx_state == Py_None)) {
    @@ -5273,7 +5392,7 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Com
       }
       __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_GOTREF(__pyx_t_1);
    -  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
    +  __pyx_t_3 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_t_1); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
       __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
       __pyx_v___pyx_result->__pyx_base.position = __pyx_t_3;
     
    @@ -5287,16 +5406,16 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Com
         PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
         __PYX_ERR(1, 13, __pyx_L1_error)
       }
    -  __pyx_t_3 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_5 = ((__pyx_t_3 > 4) != 0);
    -  if (__pyx_t_5) {
    +  __pyx_t_5 = PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_6 = ((__pyx_t_5 > 4) != 0);
    +  if (__pyx_t_6) {
       } else {
    -    __pyx_t_4 = __pyx_t_5;
    +    __pyx_t_4 = __pyx_t_6;
         goto __pyx_L4_bool_binop_done;
       }
    -  __pyx_t_5 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    -  __pyx_t_6 = (__pyx_t_5 != 0);
    -  __pyx_t_4 = __pyx_t_6;
    +  __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error)
    +  __pyx_t_7 = (__pyx_t_6 != 0);
    +  __pyx_t_4 = __pyx_t_7;
       __pyx_L4_bool_binop_done:;
       if (__pyx_t_4) {
     
    @@ -5305,33 +5424,33 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Com
      *     if len(__pyx_state) > 4 and hasattr(__pyx_result, '__dict__'):
      *         __pyx_result.__dict__.update(__pyx_state[4])             # <<<<<<<<<<<<<<
      */
    -    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_7);
    -    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_8);
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_update); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_9);
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (unlikely(__pyx_v___pyx_state == Py_None)) {
           PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
           __PYX_ERR(1, 14, __pyx_L1_error)
         }
    -    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 14, __pyx_L1_error)
    -    __Pyx_GOTREF(__pyx_t_7);
    -    __pyx_t_9 = NULL;
    -    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    -      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
    -      if (likely(__pyx_t_9)) {
    -        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    -        __Pyx_INCREF(__pyx_t_9);
    +    __pyx_t_8 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 14, __pyx_L1_error)
    +    __Pyx_GOTREF(__pyx_t_8);
    +    __pyx_t_10 = NULL;
    +    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
    +      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
    +      if (likely(__pyx_t_10)) {
    +        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
    +        __Pyx_INCREF(__pyx_t_10);
             __Pyx_INCREF(function);
    -        __Pyx_DECREF_SET(__pyx_t_8, function);
    +        __Pyx_DECREF_SET(__pyx_t_9, function);
           }
         }
    -    __pyx_t_1 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_7);
    -    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    -    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    +    __pyx_t_1 = (__pyx_t_10) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_10, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8);
    +    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    +    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
         if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error)
         __Pyx_GOTREF(__pyx_t_1);
    -    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    +    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
         __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
     
         /* "(tree fragment)":13
    @@ -5355,9 +5474,9 @@ static PyObject *__pyx_f_17clickhouse_driver_14bufferedwriter___pyx_unpickle_Com
       goto __pyx_L0;
       __pyx_L1_error:;
       __Pyx_XDECREF(__pyx_t_1);
    -  __Pyx_XDECREF(__pyx_t_7);
       __Pyx_XDECREF(__pyx_t_8);
       __Pyx_XDECREF(__pyx_t_9);
    +  __Pyx_XDECREF(__pyx_t_10);
       __Pyx_AddTraceback("clickhouse_driver.bufferedwriter.__pyx_unpickle_CompressedBufferedWriter__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
       __pyx_r = 0;
       __pyx_L0:;
    @@ -5390,9 +5509,9 @@ static void __pyx_tp_dealloc_17clickhouse_driver_14bufferedwriter_BufferedWriter
       {
         PyObject *etype, *eval, *etb;
         PyErr_Fetch(&etype, &eval, &etb);
    -    ++Py_REFCNT(o);
    +    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
         __pyx_pw_17clickhouse_driver_14bufferedwriter_14BufferedWriter_3__dealloc__(o);
    -    --Py_REFCNT(o);
    +    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
         PyErr_Restore(etype, eval, etb);
       }
       (*Py_TYPE(o)->tp_free)(o);
    @@ -5915,6 +6034,9 @@ static int __Pyx_modinit_function_export_code(void) {
     
     static int __Pyx_modinit_type_init_code(void) {
       __Pyx_RefNannyDeclarations
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
       /*--- Type init code ---*/
       __pyx_vtabptr_17clickhouse_driver_14bufferedwriter_BufferedWriter = &__pyx_vtable_17clickhouse_driver_14bufferedwriter_BufferedWriter;
    @@ -5971,6 +6093,9 @@ static int __Pyx_modinit_type_init_code(void) {
     static int __Pyx_modinit_type_import_code(void) {
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
       /*--- Type import code ---*/
       __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 9, __pyx_L1_error)
    @@ -6019,17 +6144,19 @@ static int __Pyx_modinit_function_import_code(void) {
     }
     
     
    -#if PY_MAJOR_VERSION < 3
    -#ifdef CYTHON_NO_PYINIT_EXPORT
    -#define __Pyx_PyMODINIT_FUNC void
    -#else
    +#ifndef CYTHON_NO_PYINIT_EXPORT
     #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
    +#elif PY_MAJOR_VERSION < 3
    +#ifdef __cplusplus
    +#define __Pyx_PyMODINIT_FUNC extern "C" void
    +#else
    +#define __Pyx_PyMODINIT_FUNC void
     #endif
     #else
    -#ifdef CYTHON_NO_PYINIT_EXPORT
    -#define __Pyx_PyMODINIT_FUNC PyObject *
    +#ifdef __cplusplus
    +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
     #else
    -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
    +#define __Pyx_PyMODINIT_FUNC PyObject *
     #endif
     #endif
     
    @@ -6112,6 +6239,9 @@ static CYTHON_SMALL_CODE int __pyx_pymod_exec_bufferedwriter(PyObject *__pyx_pyi
     {
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannyDeclarations
       #if CYTHON_PEP489_MULTI_PHASE_INIT
       if (__pyx_m) {
    @@ -6200,15 +6330,15 @@ if (!__Pyx_RefNanny) {
       }
       #endif
       /*--- Builtin init code ---*/
    -  if (__Pyx_InitCachedBuiltins() < 0) goto __pyx_L1_error;
    +  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
       /*--- Constants init code ---*/
    -  if (__Pyx_InitCachedConstants() < 0) goto __pyx_L1_error;
    +  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
       /*--- Global type/function init code ---*/
       (void)__Pyx_modinit_global_init_code();
       (void)__Pyx_modinit_variable_export_code();
       (void)__Pyx_modinit_function_export_code();
    -  if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error;
    -  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
    +  if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    +  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
       (void)__Pyx_modinit_variable_import_code();
       (void)__Pyx_modinit_function_import_code();
       /*--- Execution code ---*/
    @@ -7711,6 +7841,37 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
         Py_XDECREF(py_frame);
     }
     
    +/* CIntToPy */
    +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_PY_LONG_LONG(unsigned PY_LONG_LONG value) {
    +    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG) ((unsigned PY_LONG_LONG) 0 - (unsigned PY_LONG_LONG) 1), const_zero = (unsigned PY_LONG_LONG) 0;
    +    const int is_unsigned = neg_one > const_zero;
    +    if (is_unsigned) {
    +        if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) {
    +            return PyInt_FromLong((long) value);
    +        } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) {
    +            return PyLong_FromUnsignedLong((unsigned long) value);
    +#ifdef HAVE_LONG_LONG
    +        } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
    +            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
    +#endif
    +        }
    +    } else {
    +        if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) {
    +            return PyInt_FromLong((long) value);
    +#ifdef HAVE_LONG_LONG
    +        } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
    +            return PyLong_FromLongLong((PY_LONG_LONG) value);
    +#endif
    +        }
    +    }
    +    {
    +        int one = 1; int little = (int)*(unsigned char *)&one;
    +        unsigned char *bytes = (unsigned char *)&value;
    +        return _PyLong_FromByteArray(bytes, sizeof(unsigned PY_LONG_LONG),
    +                                     little, !is_unsigned);
    +    }
    +}
    +
     /* CIntFromPyVerify */
     #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
         __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
    @@ -7764,6 +7925,195 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
         }
     }
     
    +/* CIntFromPy */
    +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_As_unsigned_PY_LONG_LONG(PyObject *x) {
    +    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG) ((unsigned PY_LONG_LONG) 0 - (unsigned PY_LONG_LONG) 1), const_zero = (unsigned PY_LONG_LONG) 0;
    +    const int is_unsigned = neg_one > const_zero;
    +#if PY_MAJOR_VERSION < 3
    +    if (likely(PyInt_Check(x))) {
    +        if (sizeof(unsigned PY_LONG_LONG) < sizeof(long)) {
    +            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, PyInt_AS_LONG(x))
    +        } else {
    +            long val = PyInt_AS_LONG(x);
    +            if (is_unsigned && unlikely(val < 0)) {
    +                goto raise_neg_overflow;
    +            }
    +            return (unsigned PY_LONG_LONG) val;
    +        }
    +    } else
    +#endif
    +    if (likely(PyLong_Check(x))) {
    +        if (is_unsigned) {
    +#if CYTHON_USE_PYLONG_INTERNALS
    +            const digit* digits = ((PyLongObject*)x)->ob_digit;
    +            switch (Py_SIZE(x)) {
    +                case  0: return (unsigned PY_LONG_LONG) 0;
    +                case  1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, digit, digits[0])
    +                case 2:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 2 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
    +                        }
    +                    }
    +                    break;
    +                case 3:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 3 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
    +                        }
    +                    }
    +                    break;
    +                case 4:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) >= 4 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
    +                        }
    +                    }
    +                    break;
    +            }
    +#endif
    +#if CYTHON_COMPILING_IN_CPYTHON
    +            if (unlikely(Py_SIZE(x) < 0)) {
    +                goto raise_neg_overflow;
    +            }
    +#else
    +            {
    +                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
    +                if (unlikely(result < 0))
    +                    return (unsigned PY_LONG_LONG) -1;
    +                if (unlikely(result == 1))
    +                    goto raise_neg_overflow;
    +            }
    +#endif
    +            if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned long)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x))
    +#ifdef HAVE_LONG_LONG
    +            } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(unsigned PY_LONG_LONG)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
    +#endif
    +            }
    +        } else {
    +#if CYTHON_USE_PYLONG_INTERNALS
    +            const digit* digits = ((PyLongObject*)x)->ob_digit;
    +            switch (Py_SIZE(x)) {
    +                case  0: return (unsigned PY_LONG_LONG) 0;
    +                case -1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, sdigit, (sdigit) (-(sdigit)digits[0]))
    +                case  1: __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG,  digit, +digits[0])
    +                case -2:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 1 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
    +                        }
    +                    }
    +                    break;
    +                case 2:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 1 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) ((((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
    +                        }
    +                    }
    +                    break;
    +                case -3:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
    +                        }
    +                    }
    +                    break;
    +                case 3:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 2 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) ((((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
    +                        }
    +                    }
    +                    break;
    +                case -4:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) (((unsigned PY_LONG_LONG)-1)*(((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
    +                        }
    +                    }
    +                    break;
    +                case 4:
    +                    if (8 * sizeof(unsigned PY_LONG_LONG) > 3 * PyLong_SHIFT) {
    +                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
    +                            __PYX_VERIFY_RETURN_INT(unsigned PY_LONG_LONG, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
    +                        } else if (8 * sizeof(unsigned PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
    +                            return (unsigned PY_LONG_LONG) ((((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])));
    +                        }
    +                    }
    +                    break;
    +            }
    +#endif
    +            if (sizeof(unsigned PY_LONG_LONG) <= sizeof(long)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, long, PyLong_AsLong(x))
    +#ifdef HAVE_LONG_LONG
    +            } else if (sizeof(unsigned PY_LONG_LONG) <= sizeof(PY_LONG_LONG)) {
    +                __PYX_VERIFY_RETURN_INT_EXC(unsigned PY_LONG_LONG, PY_LONG_LONG, PyLong_AsLongLong(x))
    +#endif
    +            }
    +        }
    +        {
    +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
    +            PyErr_SetString(PyExc_RuntimeError,
    +                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
    +#else
    +            unsigned PY_LONG_LONG val;
    +            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
    + #if PY_MAJOR_VERSION < 3
    +            if (likely(v) && !PyLong_Check(v)) {
    +                PyObject *tmp = v;
    +                v = PyNumber_Long(tmp);
    +                Py_DECREF(tmp);
    +            }
    + #endif
    +            if (likely(v)) {
    +                int one = 1; int is_little = (int)*(unsigned char *)&one;
    +                unsigned char *bytes = (unsigned char *)&val;
    +                int ret = _PyLong_AsByteArray((PyLongObject *)v,
    +                                              bytes, sizeof(val),
    +                                              is_little, !is_unsigned);
    +                Py_DECREF(v);
    +                if (likely(!ret))
    +                    return val;
    +            }
    +#endif
    +            return (unsigned PY_LONG_LONG) -1;
    +        }
    +    } else {
    +        unsigned PY_LONG_LONG val;
    +        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
    +        if (!tmp) return (unsigned PY_LONG_LONG) -1;
    +        val = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(tmp);
    +        Py_DECREF(tmp);
    +        return val;
    +    }
    +raise_overflow:
    +    PyErr_SetString(PyExc_OverflowError,
    +        "value too large to convert to unsigned PY_LONG_L
    ... [truncated]
    
  • clickhouse_driver/bufferedwriter.pyx+5 5 modified
    @@ -7,9 +7,9 @@ from .varint import write_varint
     
     cdef class BufferedWriter(object):
         cdef char* buffer
    -    cdef Py_ssize_t position, buffer_size
    +    cdef unsigned long long position, buffer_size
     
    -    def __init__(self, Py_ssize_t bufsize):
    +    def __init__(self, unsigned long long bufsize):
             self.buffer = <char *> PyMem_Malloc(bufsize)
             if not self.buffer:
                 raise MemoryError()
    @@ -26,9 +26,9 @@ cdef class BufferedWriter(object):
             raise NotImplementedError
     
         cpdef write(self, data):
    -        cdef Py_ssize_t written = 0
    -        cdef Py_ssize_t to_write, size
    -        cdef Py_ssize_t data_len = len(data)
    +        cdef unsigned long long written = 0
    +        cdef unsigned long long to_write, size
    +        cdef unsigned long long data_len = len(data)
             cdef char* c_data
     
             c_data = PyBytes_AsString(data)
    
  • clickhouse_driver/columns/stringcolumn.c+108 19 modified
    @@ -1,4 +1,4 @@
    -/* Generated by Cython 0.29.17 */
    +/* Generated by Cython 0.29.21 */
     
     /* BEGIN: Cython Metadata
     {
    @@ -20,8 +20,8 @@ END: Cython Metadata */
     #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
         #error Cython requires Python 2.6+ or Python 3.3+.
     #else
    -#define CYTHON_ABI "0_29_17"
    -#define CYTHON_HEX_VERSION 0x001D11F0
    +#define CYTHON_ABI "0_29_21"
    +#define CYTHON_HEX_VERSION 0x001D15F0
     #define CYTHON_FUTURE_DIVISION 1
     #include <stddef.h>
     #ifndef offsetof
    @@ -448,7 +448,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
       #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
       #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
    +  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
       #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    +  #else
    +  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
    +  #endif
     #else
       #define CYTHON_PEP393_ENABLED 0
       #define PyUnicode_1BYTE_KIND  1
    @@ -511,6 +515,13 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
     #ifndef PySet_CheckExact
       #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
     #endif
    +#if PY_VERSION_HEX >= 0x030900A4
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
    +#else
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
    +#endif
     #if CYTHON_ASSUME_SAFE_MACROS
       #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
     #else
    @@ -550,7 +561,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
     #endif
     #if PY_MAJOR_VERSION >= 3
    -  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
    +  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
     #else
       #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
     #endif
    @@ -591,11 +602,10 @@ static CYTHON_INLINE float __PYX_NAN() {
     #define __Pyx_truncl truncl
     #endif
     
    -
    +#define __PYX_MARK_ERR_POS(f_index, lineno) \
    +    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
     #define __PYX_ERR(f_index, lineno, Ln_error) \
    -{ \
    -  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
    -}
    +    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
     
     #ifndef __PYX_EXTERN_C
       #ifdef __cplusplus
    @@ -1660,6 +1670,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_2__default
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__defaults__", 0);
       __Pyx_XDECREF(__pyx_r);
       __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
    @@ -1698,6 +1711,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_6String_1_
       PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_encoding = 0;
       PyObject *__pyx_v_kwargs = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -1768,6 +1784,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_6String___
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":23
    @@ -1844,6 +1863,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_6String_3w
       PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_items = 0;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("write_items (wrapper)", 0);
    @@ -1917,6 +1939,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_6String_2w
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":27
    @@ -1985,6 +2010,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_6String_5r
       PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_n_items = 0;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("read_items (wrapper)", 0);
    @@ -2058,6 +2086,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_6String_4r
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":30
    @@ -2127,6 +2158,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_10ByteStri
       CYTHON_UNUSED PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_items = 0;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("write_items (wrapper)", 0);
    @@ -2199,6 +2233,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_10ByteStri
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":38
    @@ -2265,6 +2302,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_10ByteStri
       CYTHON_UNUSED PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_n_items = 0;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("read_items (wrapper)", 0);
    @@ -2337,6 +2377,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_10ByteStri
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
       PyObject *__pyx_t_3 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":41
    @@ -2404,6 +2447,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_11FixedStr
       PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_length = 0;
       PyObject *__pyx_v_kwargs = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
    @@ -2469,6 +2515,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_11FixedStr
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
       PyObject *__pyx_t_2 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__init__", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":48
    @@ -2545,6 +2594,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_11FixedStr
       PyObject *__pyx_v_self = 0;
       Py_ssize_t __pyx_v_n_items;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("read_items (wrapper)", 0);
    @@ -2638,6 +2690,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_11FixedStr
       PyObject *__pyx_t_12 = NULL;
       PyObject *__pyx_t_13 = NULL;
       int __pyx_t_14;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":52
    @@ -3031,6 +3086,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_11FixedStr
       PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_items = 0;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("write_items (wrapper)", 0);
    @@ -3117,6 +3175,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_11FixedStr
       PyObject *__pyx_t_7 = NULL;
       Py_ssize_t __pyx_t_8;
       char *__pyx_t_9;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":84
    @@ -3481,6 +3542,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_15ByteFixe
       PyObject *__pyx_v_self = 0;
       Py_ssize_t __pyx_v_n_items;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("read_items (wrapper)", 0);
    @@ -3564,6 +3628,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_15ByteFixe
       char *__pyx_t_6;
       Py_ssize_t __pyx_t_7;
       Py_ssize_t __pyx_t_8;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":120
    @@ -3726,6 +3793,9 @@ static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_15ByteFixe
       PyObject *__pyx_v_self = 0;
       PyObject *__pyx_v_items = 0;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("write_items (wrapper)", 0);
    @@ -3811,6 +3881,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_15ByteFixe
       PyObject *__pyx_t_7 = NULL;
       PyObject *__pyx_t_8 = NULL;
       char *__pyx_t_9;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_items", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":132
    @@ -4115,6 +4188,9 @@ static PyMethodDef __pyx_mdef_17clickhouse_driver_7columns_12stringcolumn_1creat
     static PyObject *__pyx_pw_17clickhouse_driver_7columns_12stringcolumn_1create_string_column(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       PyObject *__pyx_v_spec = 0;
       PyObject *__pyx_v_column_options = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("create_string_column (wrapper)", 0);
    @@ -4186,6 +4262,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_7columns_12stringcolumn_create_str
       int __pyx_t_5;
       PyObject *__pyx_t_6 = NULL;
       int __pyx_t_7;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("create_string_column", 0);
     
       /* "clickhouse_driver/columns/stringcolumn.pyx":159
    @@ -4790,6 +4869,9 @@ static int __Pyx_modinit_type_init_code(void) {
     static int __Pyx_modinit_type_import_code(void) {
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
       /*--- Type import code ---*/
       __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error)
    @@ -4838,17 +4920,19 @@ static int __Pyx_modinit_function_import_code(void) {
     }
     
     
    -#if PY_MAJOR_VERSION < 3
    -#ifdef CYTHON_NO_PYINIT_EXPORT
    -#define __Pyx_PyMODINIT_FUNC void
    -#else
    +#ifndef CYTHON_NO_PYINIT_EXPORT
     #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
    +#elif PY_MAJOR_VERSION < 3
    +#ifdef __cplusplus
    +#define __Pyx_PyMODINIT_FUNC extern "C" void
    +#else
    +#define __Pyx_PyMODINIT_FUNC void
     #endif
     #else
    -#ifdef CYTHON_NO_PYINIT_EXPORT
    -#define __Pyx_PyMODINIT_FUNC PyObject *
    +#ifdef __cplusplus
    +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
     #else
    -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
    +#define __Pyx_PyMODINIT_FUNC PyObject *
     #endif
     #endif
     
    @@ -4934,6 +5018,9 @@ static CYTHON_SMALL_CODE int __pyx_pymod_exec_stringcolumn(PyObject *__pyx_pyini
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannyDeclarations
       #if CYTHON_PEP489_MULTI_PHASE_INIT
       if (__pyx_m) {
    @@ -5022,15 +5109,15 @@ if (!__Pyx_RefNanny) {
       }
       #endif
       /*--- Builtin init code ---*/
    -  if (__Pyx_InitCachedBuiltins() < 0) goto __pyx_L1_error;
    +  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
       /*--- Constants init code ---*/
    -  if (__Pyx_InitCachedConstants() < 0) goto __pyx_L1_error;
    +  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
       /*--- Global type/function init code ---*/
       (void)__Pyx_modinit_global_init_code();
       (void)__Pyx_modinit_variable_export_code();
       (void)__Pyx_modinit_function_export_code();
       (void)__Pyx_modinit_type_init_code();
    -  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
    +  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
       (void)__Pyx_modinit_variable_import_code();
       (void)__Pyx_modinit_function_import_code();
       /*--- Execution code ---*/
    @@ -6085,7 +6172,7 @@ static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
                 stop += length;
         }
         if (unlikely(stop <= start))
    -        return PyUnicode_FromUnicode(NULL, 0);
    +        return __Pyx_NewRef(__pyx_empty_unicode);
         length = stop - start;
         cstring += start;
         if (decode_func) {
    @@ -7736,6 +7823,7 @@ static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit,
     }
     static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
     {
    +#if PY_MAJOR_VERSION < 3
         __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
         if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
             Py_INCREF(func);
    @@ -7748,6 +7836,7 @@ static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObj
         }
         if (obj == Py_None)
             obj = NULL;
    +#endif
         return __Pyx_PyMethod_New(func, obj, type);
     }
     static PyObject*
    
  • clickhouse_driver/varint.c+45 18 modified
    @@ -1,4 +1,4 @@
    -/* Generated by Cython 0.29.17 */
    +/* Generated by Cython 0.29.21 */
     
     /* BEGIN: Cython Metadata
     {
    @@ -20,8 +20,8 @@ END: Cython Metadata */
     #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
         #error Cython requires Python 2.6+ or Python 3.3+.
     #else
    -#define CYTHON_ABI "0_29_17"
    -#define CYTHON_HEX_VERSION 0x001D11F0
    +#define CYTHON_ABI "0_29_21"
    +#define CYTHON_HEX_VERSION 0x001D15F0
     #define CYTHON_FUTURE_DIVISION 1
     #include <stddef.h>
     #ifndef offsetof
    @@ -448,7 +448,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
       #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
       #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
    +  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
       #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    +  #else
    +  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
    +  #endif
     #else
       #define CYTHON_PEP393_ENABLED 0
       #define PyUnicode_1BYTE_KIND  1
    @@ -511,6 +515,13 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
     #ifndef PySet_CheckExact
       #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
     #endif
    +#if PY_VERSION_HEX >= 0x030900A4
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
    +#else
    +  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
    +  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
    +#endif
     #if CYTHON_ASSUME_SAFE_MACROS
       #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
     #else
    @@ -550,7 +561,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
       #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
     #endif
     #if PY_MAJOR_VERSION >= 3
    -  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
    +  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func))
     #else
       #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
     #endif
    @@ -591,11 +602,10 @@ static CYTHON_INLINE float __PYX_NAN() {
     #define __Pyx_truncl truncl
     #endif
     
    -
    +#define __PYX_MARK_ERR_POS(f_index, lineno) \
    +    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
     #define __PYX_ERR(f_index, lineno, Ln_error) \
    -{ \
    -  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
    -}
    +    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }
     
     #ifndef __PYX_EXTERN_C
       #ifdef __cplusplus
    @@ -1247,6 +1257,9 @@ static PyMethodDef __pyx_mdef_17clickhouse_driver_6varint_1write_varint = {"writ
     static PyObject *__pyx_pw_17clickhouse_driver_6varint_1write_varint(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
       unsigned PY_LONG_LONG __pyx_v_number;
       PyObject *__pyx_v_buf = 0;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       PyObject *__pyx_r = 0;
       __Pyx_RefNannyDeclarations
       __Pyx_RefNannySetupContext("write_varint (wrapper)", 0);
    @@ -1314,6 +1327,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_write_varint(CYTHON_UNUSED
       PyObject *__pyx_t_3 = NULL;
       PyObject *__pyx_t_4 = NULL;
       PyObject *__pyx_t_5 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("write_varint", 0);
     
       /* "clickhouse_driver/varint.pyx":8
    @@ -1510,6 +1526,9 @@ static PyObject *__pyx_pf_17clickhouse_driver_6varint_2read_varint(CYTHON_UNUSED
       PyObject *__pyx_t_3 = NULL;
       unsigned PY_LONG_LONG __pyx_t_4;
       int __pyx_t_5;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("read_varint", 0);
     
       /* "clickhouse_driver/varint.pyx":32
    @@ -1814,6 +1833,9 @@ static int __Pyx_modinit_type_init_code(void) {
     static int __Pyx_modinit_type_import_code(void) {
       __Pyx_RefNannyDeclarations
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
       /*--- Type import code ---*/
       __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error)
    @@ -1862,17 +1884,19 @@ static int __Pyx_modinit_function_import_code(void) {
     }
     
     
    -#if PY_MAJOR_VERSION < 3
    -#ifdef CYTHON_NO_PYINIT_EXPORT
    -#define __Pyx_PyMODINIT_FUNC void
    -#else
    +#ifndef CYTHON_NO_PYINIT_EXPORT
     #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
    +#elif PY_MAJOR_VERSION < 3
    +#ifdef __cplusplus
    +#define __Pyx_PyMODINIT_FUNC extern "C" void
    +#else
    +#define __Pyx_PyMODINIT_FUNC void
     #endif
     #else
    -#ifdef CYTHON_NO_PYINIT_EXPORT
    -#define __Pyx_PyMODINIT_FUNC PyObject *
    +#ifdef __cplusplus
    +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
     #else
    -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
    +#define __Pyx_PyMODINIT_FUNC PyObject *
     #endif
     #endif
     
    @@ -1954,6 +1978,9 @@ static CYTHON_SMALL_CODE int __pyx_pymod_exec_varint(PyObject *__pyx_pyinit_modu
     #endif
     {
       PyObject *__pyx_t_1 = NULL;
    +  int __pyx_lineno = 0;
    +  const char *__pyx_filename = NULL;
    +  int __pyx_clineno = 0;
       __Pyx_RefNannyDeclarations
       #if CYTHON_PEP489_MULTI_PHASE_INIT
       if (__pyx_m) {
    @@ -2042,15 +2069,15 @@ if (!__Pyx_RefNanny) {
       }
       #endif
       /*--- Builtin init code ---*/
    -  if (__Pyx_InitCachedBuiltins() < 0) goto __pyx_L1_error;
    +  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
       /*--- Constants init code ---*/
    -  if (__Pyx_InitCachedConstants() < 0) goto __pyx_L1_error;
    +  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
       /*--- Global type/function init code ---*/
       (void)__Pyx_modinit_global_init_code();
       (void)__Pyx_modinit_variable_export_code();
       (void)__Pyx_modinit_function_export_code();
       (void)__Pyx_modinit_type_init_code();
    -  if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
    +  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
       (void)__Pyx_modinit_variable_import_code();
       (void)__Pyx_modinit_function_import_code();
       /*--- Execution code ---*/
    
  • tests/test_buffered_reader.py+23 0 added
    @@ -0,0 +1,23 @@
    +import socket
    +from unittest import TestCase
    +
    +import mock
    +from clickhouse_driver.bufferedreader import BufferedSocketReader
    +
    +
    +class BufferedReaderTestCase(TestCase):
    +    def test_overflow_signed_int_string_size(self):
    +        data = b'\xFF\xFE\xFC\xFE\x29\x80\x40\x00\x00\x01'
    +
    +        def recv_into(buf):
    +            size = len(data)
    +            buf[0:size] = data
    +            return size
    +
    +        with mock.patch('socket.socket') as mock_socket:
    +            mock_socket.return_value.recv_into.side_effect = recv_into
    +            reader = BufferedSocketReader(socket.socket(), 1024)
    +
    +            # Trying to allocate huge amount of memory.
    +            with self.assertRaises(MemoryError):
    +                reader.read_strings(5, encoding='utf-8')
    
  • .travis.yml+31 0 modified
    @@ -65,6 +65,37 @@ after_success:
     
     jobs:
       include:
    +    - stage: valgrind
    +      name: Valgrind check
    +      os: linux
    +      language: python
    +      python:
    +        - "3.6"
    +      addons:
    +        apt:
    +          packages:
    +            - valgrind
    +      install:
    +        - docker run -e "TZ=Europe/Moscow" -d -p 127.0.0.1:9000:9000 --name test-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server:$VERSION
    +        - docker run -d --entrypoint "/bin/sh" --name test-clickhouse-client --link test-clickhouse-server:clickhouse-server yandex/clickhouse-client:$VERSION -c 'while :; do sleep 1; done'
    +        - docker ps -a
    +        # Faking clickhouse-client real communication with container via docker exec.
    +        - echo -e '#!/bin/bash\n\ndocker exec -e "`env | grep ^TZ=`" test-clickhouse-client clickhouse-client "$@"' | sudo tee /usr/local/bin/clickhouse-client > /dev/null
    +        - sudo chmod +x /usr/local/bin/clickhouse-client
    +        # Overriding setup.cfg. Set host=clickhouse-server
    +        - sed -i 's/^host=localhost$/host=clickhouse-server/' setup.cfg
    +        # Make host think that clickhouse-server is localhost
    +        - echo '127.0.0.1 clickhouse-server' | sudo tee /etc/hosts > /dev/null
    +        - pip install --upgrade pip setuptools
    +        - pip install cython
    +
    +      script:
    +        - valgrind --error-exitcode=1 python setup.py test
    +
    +      env:
    +        - VERSION=20.3.7.46
    +        - PYTHONMALLOC=malloc
    +
         - stage: wheels
           name: Wheels for Linux
           os: linux
    

Vulnerability mechanics

Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

5

News mentions

0

No linked articles in our index yet.