8000 Add one char to MsiSummaryInfoGetProperty() output · python/cpython@6e4a70f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e4a70f

Browse files
committed
Add one char to MsiSummaryInfoGetProperty() output
Based on the patch in bpo-1104 by Anthony Tuininga (atuining) and Mark Mc Mahon (markm). Unfortunately Microsoft has deemed it necessary to return the size of the string without the null termination character but insists upon the size including it when passing it in. Arggh! -- Anthony, on the fix
1 parent 3df02db commit 6e4a70f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Lib/test/test_msilib.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Test suite for the code in msilib """
2+
import os
23
import unittest
34
from test.support import TESTFN, import_module, unlink
45
msilib = import_module('msilib')
@@ -41,6 +42,29 @@ def test_view_fetch_returns_none(self):
4142
)
4243
self.addCleanup(unlink, db_path)
4344

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+
4468

4569
class Test_make_id(unittest.TestCase):
4670
#http://msdn.microsoft.com/en-us/library/aa369212(v=vs.85).aspx
@@ -73,7 +97,7 @@ def test_invalid_first_char(self):
7397
def test_invalid_any_char(self):
7498
self.assertEqual(
7599
msilib.make_id(".s\x82ort"), "_.s_ort")
76-
self.assertEqual (
100+
self.assertEqual(
77101
msilib.make_id(".s\x82o?*+rt"), "_.s_o___rt")
78102

79103

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,15 @@ summary_getproperty(msiobj* si, PyObject *args)
545545
FILETIME fval;
546546
char sbuf[1000];
547547
char *sval = sbuf;
548-
DWORD ssize = sizeof(sval);
548+
DWORD ssize = sizeof(sbuf);
549549

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

553553
status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
554554
&fval, sval, &ssize);
555555
if (status == ERROR_MORE_DATA) {
556+
ssize++;
556557
sval = malloc(ssize);
557558
status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
558559
&fval, sval, &ssize);

0 commit comments

Comments
 (0)
0