8000 bpo-1104: msilib.SummaryInfo.GetProperty() truncates the string by on… · python/cpython@2de576e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2de576e

Browse files
uranusjrzooba
authored andcommitted
bpo-1104: msilib.SummaryInfo.GetProperty() truncates the string by one character (GH-4517)
Add one char to MsiSummaryInfoGetProperty() output Based on the patch in bpo-1104 by Anthony Tuininga (atuining) and Mark McMahon (markm).
1 parent 05e9221 commit 2de576e

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

Lib/test/test_msilib.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
""" Test suite for the code in msilib """
2-
import os.path
2+
import os
33
import unittest
44
from test.support import TESTFN, import_module, unlink
55
msilib = import_module('msilib')
@@ -42,6 +42,29 @@ def test_view_fetch_returns_none(self):
4242
)
4343
self.addCleanup(unlink, db_path)
4444

45+
def test_summaryinfo_getproperty_issue1104(self):
46+
db, db_path = init_database()
47+
try:
48+
sum_info = db.GetSummaryInformation(99)
49+
title = sum_info.GetProperty(msilib.PID_TITLE)
50+
self.assertEqual(title, b"Installation Database")
51+
52+
sum_info.SetProperty(msilib.PID_TITLE, "a" * 999)
53+
title = sum_info.GetProperty(msilib.PID_TITLE)
54+
self.assertEqual(title, b"a" * 999)
55+
56+
sum_info.SetProperty(msilib.PID_TITLE, "a" * 1000)
57+
title = sum_info.GetProperty(msilib.PID_TITLE)
58+
self.assertEqual(title, b"a" * 1000)
59+
60+
sum_info.SetProperty(msilib.PID_TITLE, "a" * 1001)
61+
title = sum_info.GetProperty(msilib.PID_TITLE)
62+
self.assertEqual(title, b"a" * 1001)
63+
finally:
64+
db = None
65+
sum_info = None
66+
os.unlink(db_path)
67+
4568
def test_database_open_failed(self):
4669
with self.assertRaises(msilib.MSIError) as cm:
4770
msilib.OpenDatabase('non-existent.msi', msilib.MSIDBOPEN_READONLY)
@@ -92,7 +115,7 @@ def test_invalid_first_char(self):
92115
def test_invalid_any_char(self):
93116
self.assertEqual(
94117
msilib.make_id(".s\x82ort"), "_.s_ort")
95-
self.assertEqual (
118+
self.assertEqual(
96119
msilib.make_id(".s\x82o?*+rt"), "_.s_o___rt")
97120

98121

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Correctly handle string length in ``msilib.SummaryInfo.GetProperty()`` to
2+
prevent it from truncating the last character.

PC/_msi.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,15 @@ summary_getproperty(msiobj* si, PyObject *args)
555555
FILETIME fval;
556556
char sbuf[1000];
557557
char *sval = sbuf;
558-
DWORD ssize = sizeof(sval);
558+
DWORD ssize = sizeof(sbuf);
559559

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

563563
status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
564564
&fval, sval, &ssize);
565565
if (status == ERROR_MORE_DATA) {
566+
ssize++;
566567
sval = malloc(ssize);
567568
if (sval == NULL) {
568569
return PyErr_NoMemory();
@@ -572,21 +573,29 @@ summary_getproperty(msiobj* si, PyObject *args)
572573
}
573574

574575
switch(type) {
575-
case VT_I2: case VT_I4:
576-
return PyLong_FromLong(ival);
576+
case VT_I2:
577+
case VT_I4:
578+
result = PyLong_FromLong(ival);
579+
break;
577580
case VT_FILETIME:
578581
PyErr_SetString(PyExc_NotImplementedError, "FILETIME result");
579-
return NULL;
582+
result = NULL;
583+
break;
580584
case VT_LPSTR:
581585
result = PyBytes_FromStringAndSize(sval, ssize);
582-
if (sval != sbuf)
583-
free(sval);
584-
return result;
586+
break;
585587
case VT_EMPTY:
586-
Py_RETURN_NONE;
588+
Py_INCREF(Py_None);
589+
result = Py_None;
590+
break;
591+
default:
592+
PyErr_Format(PyExc_NotImplementedError, "result of type %d", type);
593+
result = NULL;
594+
break;
587595
}
588-
PyErr_Format(PyExc_NotImplementedError, "result of type %d", type);
589-
return NULL;
596+
if (sval != sbuf)
597+
free(sval);
598+
return result;
590599
}
591600

592601
static PyObject*

0 commit comments

Comments
 (0)
0