[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-11 Thread David Wood


Change by David Wood :


Removed file: https://bugs.python.org/file49861/crypt.tar.gz

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-10 Thread David Wood


David Wood  added the comment:

Christian/Eric -

Thank you both so much for taking time on this.  Christian had pointed out the 
use of memcpy vs strncpy.  It turns out that while strncpy is designed to copy 
a specific number of chars, it turns out that it stops on null.  I did make the 
change Christian suggested however, it turns out that strncpy was also used in 
the decrypt function which was also subject to the same problem.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-09 Thread David Wood


Change by David Wood :


Removed file: https://bugs.python.org/file49862/crypt.tar.gz

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-09 Thread David Wood


David Wood  added the comment:

Attached are the basic files.  As you can see in the example test9.py, I am 
generating a random string, encrypting it, decrypting it, and comparing the 
decrypted result with the original value.

This is intended to run on linux and requires the mcrypt library (libmcrypt-dev 
on debian based distro).  I'm at a loss and any help is greatly appreciated.

--
Added file: https://bugs.python.org/file49861/crypt.tar.gz

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-09 Thread David Wood


Change by David Wood :


Added file: https://bugs.python.org/file49862/crypt.tar.gz

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-08 Thread David Wood


David Wood  added the comment:

Still no bueno.

--

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-08 Thread David Wood


David Wood  added the comment:

Christian -

Thank you for this.  I did as you suggested however, I still have the same 
problem.  As I pointed out in my original message, the problem does not exist 
if I insert a sleep(1) statement prior to returning from the function.  
Additional to that, I previously had printf('.') statement in place of the 
sleep statement.  When I ran 10,000 iterations in python and printed my 
pass/fail totals, I still had a few hundred dots print which tells me that 
there has to be some sort of timing or buffer transfer issue between c and 
python.  Does that make sense?

--

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-08 Thread David Wood


David Wood  added the comment:

I have not gone to the extent of comparing the direct output against what 
python gets, although it appears to be incomplete.  The following is my encrypt 
function which has been used successfully for many years in a separate c 
program, so I have high confidence in it.

char * encryptBlowfishCfb(const char * inStr, Py_ssize_t *count, char * output, 
char * encrkey) {
MCRYPT td;
char IV[10];
int len, i;
char block_buffer[512];
time_t t;

srand((unsigned) time());
strcpy(IV, "");
for (i = 0 ; i < 8 ; i++ ) {
IV[i] =  mset[(rand() % 62)];
}
td = mcrypt_module_open(MCRYPT_BLOWFISH, NULL, MCRYPT_CFB, NULL);
mcrypt_generic_init(td, encrkey, strlen(encrkey), IV);
memset(block_buffer, 0, sizeof(block_buffer));
strcpy(block_buffer, inStr);
i = strlen(inStr);
mcrypt_generic(td, _buffer, i);
block_buffer[i] = '\0';
strcpy(_buffer[i], IV);
mcrypt_generic_deinit(td);
mcrypt_module_close(td);

len = i + 8 + 1;
memset(output, 0, 512);
strncpy(output, block_buffer, len -1);
*count = i + 8;

return output;
}

--

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43435] Py_BuildValue("y#".... returns incomplete result

2021-03-08 Thread David Wood


New submission from David Wood :

I have a c function to encrypt values which returns an array of bytes.  The 
function returns proper values outside of python.  When used as a python 
function, the result is incomplete usually 10-20% of the time.  If I add a 
sleep(1) call before returning from the function, my success rate goes to 100%. 
 While this works, it is unacceptable as it will create enormous latency in my 
application.

static PyObject *method_encrypt(PyObject *self, PyObject *args) {
char *keyval, *str = NULL, output[512];
Py_ssize_t count=0;
PyObject *retval;

if(!PyArg_ParseTuple(args, "ss", , )) {
return NULL;
}

encryptBlowfishCfb(str, , output, keyval);

retval = Py_BuildValue("y#", output, count);
//sleep(1);
return retval;
}

--
components: C API
messages: 388268
nosy: dwoodjunkmail
priority: normal
severity: normal
status: open
title: Py_BuildValue("y#" returns incomplete result
type: performance
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue43435>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com