mhammond / pywin32

Python for Windows (pywin32) Extensions
4.91k stars 783 forks source link

Signed values are converted tu unsigned values in SAFEARRAYs #652

Open ghost opened 10 years ago

ghost commented 10 years ago

In case a server transports VT_I1 SAFEARRAYs to the client a wrong interpretation to VT_UI1 is done in Python. Hence the client retrieves wrong data, i.e. -128 is transformed to +128. The attached patch fixes the problem.

Reported by: sschukat

Original Ticket: pywin32/bugs/652

Avasam commented 3 months ago

Tagging @sschukat as the original SourceForge issue creator.

Proposed patch with updated formatting and location:

diff --git a/com/win32com/src/oleargs.cpp b/com/win32com/src/oleargs.cpp
index c6fad6c2..bffc6346 100644
--- a/com/win32com/src/oleargs.cpp
+++ b/com/win32com/src/oleargs.cpp
@@ -901,7 +901,14 @@ static PyObject *PyCom_PyObjectFromSAFEARRAYDimensionItem(SAFEARRAY *psa, VARENU
             // case VT_DECIMAL
             // case VT_RECORD

-        case VT_I1:
+        case VT_I1: {
+            char i1;
+            hres = SafeArrayGetElement(psa, arrayIndices, &i1);
+            if (FAILED(hres))
+                break;
+            subitem = PyInt_FromLong(i1);
+            break;
+        }
         case VT_UI1: {
             unsigned char i1;
             hres = SafeArrayGetElement(psa, arrayIndices, &i1);