8000 [2.7] bpo-1104: msilib.SummaryInfo.GetProperty() truncates the string by one character (GH-4517) by uranusjr · Pull Request #11749 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[2.7] bpo-1104: msilib.SummaryInfo.GetProperty() truncates the string by one character (GH-4517) #11749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions Lib/test/test_msilib.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
""" Test suite for the code in msilib """
import unittest
import os
from test_support import run_unittest, import_module
from test_support import TESTFN, import_module, run_unittest, unlink
msilib = import_module('msilib')
import msilib.schema


def init_database():
path = TESTFN + '.msi'
db = msilib.init_database(
path,
msilib.schema,
'Python Tests',
'product_code',
'1.0',
'PSF',
)
return db, path


class MsiDatabaseTestCase(unittest.TestCase):

def test_summaryinfo_getproperty_issue1104(self):
db, db_path = init_database()
try:
sum_info = db.GetSummaryInformation(99)
title = sum_info.GetProperty(msilib.PID_TITLE)
self.assertEqual(title, b"Installation Database")

sum_info.SetProperty(msilib.PID_TITLE, & 10000 quot;a" * 999)
title = sum_info.GetProperty(msilib.PID_TITLE)
self.assertEqual(title, b"a" * 999)

sum_info.SetProperty(msilib.PID_TITLE, "a" * 1000)
title = sum_info.GetProperty(msilib.PID_TITLE)
self.assertEqual(title, b"a" * 1000)

sum_info.SetProperty(msilib.PID_TITLE, "a" * 1001)
title = sum_info.GetProperty(msilib.PID_TITLE)
self.assertEqual(title, b"a" * 1001)
finally:
db = None
sum_info = None
unlink(db_path)


class Test_make_id(unittest.TestCase):
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
Expand Down Expand Up @@ -35,12 +75,13 @@ def test_invalid_first_char(self):
def test_invalid_any_char(self):
self.assertEqual(
msilib.make_id(".s\x82ort"), "_.s_ort")
self.assertEqual (
self.assertEqual(
msilib.make_id(".s\x82o?*+rt"), "_.s_o___rt")


def test_main():
run_unittest(__name__)


if __name__ == '__main__':
test_main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Correctly handle string length in ``msilib.SummaryInfo.GetProperty()`` to
prevent it from truncating the last character.
31 changes: 21 additions & 10 deletions PC/_msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,15 @@ summary_getproperty(msiobj* si, PyObject *args)
FILETIME fval;
char sbuf[1000];
char *sval = sbuf;
DWORD ssize = sizeof(sval);
DWORD ssize = sizeof(sbuf);

if (!PyArg_ParseTuple(args, "i:GetProperty", &field))
return NULL;

status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
&fval, sval, &ssize);
if (status == ERROR_MORE_DATA) {
ssize++;
sval = malloc(ssize);
if (sval == NULL) {
return PyErr_NoMemory();
Expand All @@ -556,19 +557,29 @@ summary_getproperty(msiobj* si, PyObject *args)
}

switch(type) {
case VT_I2: case VT_I4:
return PyInt_FromLong(ival);
case VT_I2:
case VT_I4:
result = PyLong_FromLong(ival);
break;
case VT_FILETIME:
PyErr_SetString(PyExc_NotImplementedError, "FILETIME result");
return NULL;
result = NULL;
break;
case VT_LPSTR:
result = PyString_FromStringAndSize(sval, ssize);
if (sval != sbuf)
free(sval);
return result;
result = PyBytes_FromStringAndSize(sval, ssize);
break;
case VT_EMPTY:
Py_INCREF(Py_None);
result = Py_None;
break;
default:
PyErr_Format(PyExc_NotImplementedError, "result of type %d", type);
result = NULL;
break;
}
PyErr_Format(PyExc_NotImplementedError, "result of type %d", type);
return NULL;
if (sval != sbuf)
free(sval);
return result;
}

static PyObject*
Expand Down
0