@@ -62,8 +62,10 @@ PyObject *decrypt_block(PyObject *self, PyObject *args) {
62
62
return NULL ;
63
63
}
64
64
65
+ PyObject *result = PyBytes_FromObject (py_data);
66
+
65
67
Py_buffer view;
66
- if (PyObject_GetBuffer (py_data , &view, PyBUF_SIMPLE) != 0 ) {
68
+ if (PyObject_GetBuffer (result , &view, PyBUF_SIMPLE) != 0 ) {
67
69
return NULL ;
68
70
}
69
71
@@ -73,22 +75,16 @@ PyObject *decrypt_block(PyObject *self, PyObject *args) {
73
75
return NULL ;
74
76
}
75
77
76
- const unsigned char *data = (unsigned char *)view.buf ;
78
+ unsigned char *data = (unsigned char *)view.buf ;
77
79
uint64_t size = (uint64_t )view.len ;
78
80
unsigned char *index_data = (unsigned char *)PyBytes_AS_STRING (py_index_bytes);
79
81
unsigned char *substitute_data = (unsigned char *)PyBytes_AS_STRING (py_substitute_bytes);
80
82
81
- unsigned char *decrypted_data = (unsigned char *)PyMem_Malloc (size + 1 );
82
- decrypted_data[size] = 0 ;
83
- memcpy (decrypted_data, data, size);
84
-
85
83
uint64_t offset = 0 ;
86
84
while (offset < size) {
87
- offset += decrypt (decrypted_data + offset, index++, size - offset, index_data, substitute_data);
85
+ offset += decrypt (data + offset, index++, size - offset, index_data, substitute_data);
88
86
}
89
87
90
- PyObject* result = PyBytes_FromStringAndSize ((const char *)decrypted_data, size);
91
- PyMem_Free (decrypted_data);
92
88
PyBuffer_Release (&view);
93
89
94
90
return result;
0 commit comments